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);
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