From 17159f66db2cbd164f705511f5ef6e5bb44e595f Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 8 Feb 2022 15:37:17 +0000 Subject: [PATCH] Remove self-listening from ExoPlayerImpl SimpleExoPlayer used to register a listener on ExoPlayerImpl for the old EventListener callbacks. Now both classes are merged, this is no longer needed and should be removed in favor of calling methods directly. #minor-release PiperOrigin-RevId: 427187875 --- .../android/exoplayer2/ExoPlayerImpl.java | 63 +++++++++---------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java index 33ebd69f73..b6079c6ed3 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/ExoPlayerImpl.java @@ -400,7 +400,6 @@ import java.util.concurrent.TimeoutException; listeners.add(analyticsCollector); bandwidthMeter.addEventListener(new Handler(applicationLooper), analyticsCollector); - listeners.add(componentListener); addAudioOffloadListener(componentListener); if (builder.foregroundModeTimeoutMs > 0) { experimentalSetForegroundModeTimeoutMs(builder.foregroundModeTimeoutMs); @@ -1784,11 +1783,21 @@ import java.util.concurrent.TimeoutException; .buildUpon() .populateFromMetadata(newPlaybackInfo.staticMetadata) .build(); - newMediaMetadata = buildUpdatedMediaMetadata(); } boolean metadataChanged = !newMediaMetadata.equals(mediaMetadata); mediaMetadata = newMediaMetadata; + boolean playWhenReadyChanged = + previousPlaybackInfo.playWhenReady != newPlaybackInfo.playWhenReady; + boolean playbackStateChanged = + previousPlaybackInfo.playbackState != newPlaybackInfo.playbackState; + if (playbackStateChanged || playWhenReadyChanged) { + updateWakeAndWifiLock(); + } + boolean isLoadingChanged = previousPlaybackInfo.isLoading != newPlaybackInfo.isLoading; + if (isLoadingChanged) { + updatePriorityTaskManagerForIsLoadingChange(newPlaybackInfo.isLoading); + } if (!previousPlaybackInfo.timeline.equals(newPlaybackInfo.timeline)) { listeners.queueEvent( @@ -1841,7 +1850,7 @@ import java.util.concurrent.TimeoutException; EVENT_MEDIA_METADATA_CHANGED, listener -> listener.onMediaMetadataChanged(finalMediaMetadata)); } - if (previousPlaybackInfo.isLoading != newPlaybackInfo.isLoading) { + if (isLoadingChanged) { listeners.queueEvent( Player.EVENT_IS_LOADING_CHANGED, listener -> { @@ -1849,20 +1858,19 @@ import java.util.concurrent.TimeoutException; listener.onIsLoadingChanged(newPlaybackInfo.isLoading); }); } - if (previousPlaybackInfo.playbackState != newPlaybackInfo.playbackState - || previousPlaybackInfo.playWhenReady != newPlaybackInfo.playWhenReady) { + if (playbackStateChanged || playWhenReadyChanged) { listeners.queueEvent( /* eventFlag= */ C.INDEX_UNSET, listener -> listener.onPlayerStateChanged( newPlaybackInfo.playWhenReady, newPlaybackInfo.playbackState)); } - if (previousPlaybackInfo.playbackState != newPlaybackInfo.playbackState) { + if (playbackStateChanged) { listeners.queueEvent( Player.EVENT_PLAYBACK_STATE_CHANGED, listener -> listener.onPlaybackStateChanged(newPlaybackInfo.playbackState)); } - if (previousPlaybackInfo.playWhenReady != newPlaybackInfo.playWhenReady) { + if (playWhenReadyChanged) { listeners.queueEvent( Player.EVENT_PLAY_WHEN_READY_CHANGED, listener -> @@ -2584,6 +2592,18 @@ import java.util.concurrent.TimeoutException; return keepSessionIdAudioTrack.getAudioSessionId(); } + private void updatePriorityTaskManagerForIsLoadingChange(boolean isLoading) { + if (priorityTaskManager != null) { + if (isLoading && !isPriorityTaskManagerRegistered) { + priorityTaskManager.add(C.PRIORITY_PLAYBACK); + isPriorityTaskManagerRegistered = true; + } else if (!isLoading && isPriorityTaskManagerRegistered) { + priorityTaskManager.remove(C.PRIORITY_PLAYBACK); + isPriorityTaskManagerRegistered = false; + } + } + } + private static DeviceInfo createDeviceInfo(StreamVolumeManager streamVolumeManager) { return new DeviceInfo( DeviceInfo.PLAYBACK_TYPE_LOCAL, @@ -2626,8 +2646,7 @@ import java.util.concurrent.TimeoutException; } private final class ComponentListener - implements Player.Listener, - VideoRendererEventListener, + implements VideoRendererEventListener, AudioRendererEventListener, TextOutput, MetadataOutput, @@ -2903,32 +2922,6 @@ import java.util.concurrent.TimeoutException; } } - // Player.Listener implementation. - - @Override - public void onIsLoadingChanged(boolean isLoading) { - if (priorityTaskManager != null) { - if (isLoading && !isPriorityTaskManagerRegistered) { - priorityTaskManager.add(C.PRIORITY_PLAYBACK); - isPriorityTaskManagerRegistered = true; - } else if (!isLoading && isPriorityTaskManagerRegistered) { - priorityTaskManager.remove(C.PRIORITY_PLAYBACK); - isPriorityTaskManagerRegistered = false; - } - } - } - - @Override - public void onPlaybackStateChanged(@State int playbackState) { - updateWakeAndWifiLock(); - } - - @Override - public void onPlayWhenReadyChanged( - boolean playWhenReady, @PlayWhenReadyChangeReason int reason) { - updateWakeAndWifiLock(); - } - // Player.AudioOffloadListener implementation. @Override