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
This commit is contained in:
tonihei 2022-02-08 15:37:17 +00:00 committed by Ian Baker
parent 80cdfd0cf0
commit 17159f66db

View File

@ -400,7 +400,6 @@ import java.util.concurrent.TimeoutException;
listeners.add(analyticsCollector); listeners.add(analyticsCollector);
bandwidthMeter.addEventListener(new Handler(applicationLooper), analyticsCollector); bandwidthMeter.addEventListener(new Handler(applicationLooper), analyticsCollector);
listeners.add(componentListener);
addAudioOffloadListener(componentListener); addAudioOffloadListener(componentListener);
if (builder.foregroundModeTimeoutMs > 0) { if (builder.foregroundModeTimeoutMs > 0) {
experimentalSetForegroundModeTimeoutMs(builder.foregroundModeTimeoutMs); experimentalSetForegroundModeTimeoutMs(builder.foregroundModeTimeoutMs);
@ -1784,11 +1783,21 @@ import java.util.concurrent.TimeoutException;
.buildUpon() .buildUpon()
.populateFromMetadata(newPlaybackInfo.staticMetadata) .populateFromMetadata(newPlaybackInfo.staticMetadata)
.build(); .build();
newMediaMetadata = buildUpdatedMediaMetadata(); newMediaMetadata = buildUpdatedMediaMetadata();
} }
boolean metadataChanged = !newMediaMetadata.equals(mediaMetadata); boolean metadataChanged = !newMediaMetadata.equals(mediaMetadata);
mediaMetadata = newMediaMetadata; 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)) { if (!previousPlaybackInfo.timeline.equals(newPlaybackInfo.timeline)) {
listeners.queueEvent( listeners.queueEvent(
@ -1841,7 +1850,7 @@ import java.util.concurrent.TimeoutException;
EVENT_MEDIA_METADATA_CHANGED, EVENT_MEDIA_METADATA_CHANGED,
listener -> listener.onMediaMetadataChanged(finalMediaMetadata)); listener -> listener.onMediaMetadataChanged(finalMediaMetadata));
} }
if (previousPlaybackInfo.isLoading != newPlaybackInfo.isLoading) { if (isLoadingChanged) {
listeners.queueEvent( listeners.queueEvent(
Player.EVENT_IS_LOADING_CHANGED, Player.EVENT_IS_LOADING_CHANGED,
listener -> { listener -> {
@ -1849,20 +1858,19 @@ import java.util.concurrent.TimeoutException;
listener.onIsLoadingChanged(newPlaybackInfo.isLoading); listener.onIsLoadingChanged(newPlaybackInfo.isLoading);
}); });
} }
if (previousPlaybackInfo.playbackState != newPlaybackInfo.playbackState if (playbackStateChanged || playWhenReadyChanged) {
|| previousPlaybackInfo.playWhenReady != newPlaybackInfo.playWhenReady) {
listeners.queueEvent( listeners.queueEvent(
/* eventFlag= */ C.INDEX_UNSET, /* eventFlag= */ C.INDEX_UNSET,
listener -> listener ->
listener.onPlayerStateChanged( listener.onPlayerStateChanged(
newPlaybackInfo.playWhenReady, newPlaybackInfo.playbackState)); newPlaybackInfo.playWhenReady, newPlaybackInfo.playbackState));
} }
if (previousPlaybackInfo.playbackState != newPlaybackInfo.playbackState) { if (playbackStateChanged) {
listeners.queueEvent( listeners.queueEvent(
Player.EVENT_PLAYBACK_STATE_CHANGED, Player.EVENT_PLAYBACK_STATE_CHANGED,
listener -> listener.onPlaybackStateChanged(newPlaybackInfo.playbackState)); listener -> listener.onPlaybackStateChanged(newPlaybackInfo.playbackState));
} }
if (previousPlaybackInfo.playWhenReady != newPlaybackInfo.playWhenReady) { if (playWhenReadyChanged) {
listeners.queueEvent( listeners.queueEvent(
Player.EVENT_PLAY_WHEN_READY_CHANGED, Player.EVENT_PLAY_WHEN_READY_CHANGED,
listener -> listener ->
@ -2584,6 +2592,18 @@ import java.util.concurrent.TimeoutException;
return keepSessionIdAudioTrack.getAudioSessionId(); 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) { private static DeviceInfo createDeviceInfo(StreamVolumeManager streamVolumeManager) {
return new DeviceInfo( return new DeviceInfo(
DeviceInfo.PLAYBACK_TYPE_LOCAL, DeviceInfo.PLAYBACK_TYPE_LOCAL,
@ -2626,8 +2646,7 @@ import java.util.concurrent.TimeoutException;
} }
private final class ComponentListener private final class ComponentListener
implements Player.Listener, implements VideoRendererEventListener,
VideoRendererEventListener,
AudioRendererEventListener, AudioRendererEventListener,
TextOutput, TextOutput,
MetadataOutput, 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. // Player.AudioOffloadListener implementation.
@Override @Override