From 121013d35e26fd887066a7e6f1dcabd950e5ab42 Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 8 Feb 2022 16:41:10 +0000 Subject: [PATCH] Avoid special-casing AnalyticsCollector when informing listeners. In some cases (whose where we previously used EventListener), AnalyticsCollector is registered as a listener to receive updates, in other cases it is called directly. Avoid this inconsistent handling by registering it as normal listener and removing all callbacks that are handled by the normal listener flow. The remaining direct usages of AnalyticsCollector calls are those callbacks that have no equivalent in Player.Listener. #minor-release PiperOrigin-RevId: 427201525 --- .../com/google/android/exoplayer2/ExoPlayerImpl.java | 12 +----------- 1 file changed, 1 insertion(+), 11 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 b6079c6ed3..721103a5be 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 @@ -398,7 +398,7 @@ import java.util.concurrent.TimeoutException; currentCues = ImmutableList.of(); throwsWhenUsingWrongThread = true; - listeners.add(analyticsCollector); + addListener(analyticsCollector); bandwidthMeter.addEventListener(new Handler(applicationLooper), analyticsCollector); addAudioOffloadListener(componentListener); if (builder.foregroundModeTimeoutMs > 0) { @@ -1382,7 +1382,6 @@ import java.util.concurrent.TimeoutException; this.audioAttributes = audioAttributes; sendRendererMessage(TRACK_TYPE_AUDIO, MSG_SET_AUDIO_ATTRIBUTES, audioAttributes); streamVolumeManager.setStreamType(Util.getStreamTypeForAudioUsage(audioAttributes.usage)); - analyticsCollector.onAudioAttributesChanged(audioAttributes); // TODO(internal b/187152483): Events should be dispatched via ListenerSet for (Listener listener : listenerArraySet) { listener.onAudioAttributesChanged(audioAttributes); @@ -1420,7 +1419,6 @@ import java.util.concurrent.TimeoutException; this.audioSessionId = audioSessionId; sendRendererMessage(TRACK_TYPE_AUDIO, MSG_SET_AUDIO_SESSION_ID, audioSessionId); sendRendererMessage(TRACK_TYPE_VIDEO, MSG_SET_AUDIO_SESSION_ID, audioSessionId); - analyticsCollector.onAudioSessionIdChanged(audioSessionId); // TODO(internal b/187152483): Events should be dispatched via ListenerSet for (Listener listener : listenerArraySet) { listener.onAudioSessionIdChanged(audioSessionId); @@ -1448,7 +1446,6 @@ import java.util.concurrent.TimeoutException; } this.volume = volume; sendVolumeToRenderers(); - analyticsCollector.onVolumeChanged(volume); // TODO(internal b/187152483): Events should be dispatched via ListenerSet for (Listener listener : listenerArraySet) { listener.onVolumeChanged(volume); @@ -2475,7 +2472,6 @@ import java.util.concurrent.TimeoutException; if (width != surfaceWidth || height != surfaceHeight) { surfaceWidth = width; surfaceHeight = height; - analyticsCollector.onSurfaceSizeChanged(width, height); // TODO(internal b/187152483): Events should be dispatched via ListenerSet for (Listener listener : listenerArraySet) { listener.onSurfaceSizeChanged(width, height); @@ -2489,7 +2485,6 @@ import java.util.concurrent.TimeoutException; } private void notifySkipSilenceEnabledChanged() { - analyticsCollector.onSkipSilenceEnabledChanged(skipSilenceEnabled); // TODO(internal b/187152483): Events should be dispatched via ListenerSet for (Listener listener : listenerArraySet) { listener.onSkipSilenceEnabledChanged(skipSilenceEnabled); @@ -2688,7 +2683,6 @@ import java.util.concurrent.TimeoutException; @Override public void onVideoSizeChanged(VideoSize videoSize) { ExoPlayerImpl.this.videoSize = videoSize; - analyticsCollector.onVideoSizeChanged(videoSize); // TODO(internal b/187152483): Events should be dispatched via ListenerSet for (Listener listener : listenerArraySet) { listener.onVideoSizeChanged(videoSize); @@ -2796,7 +2790,6 @@ import java.util.concurrent.TimeoutException; @Override public void onCues(List cues) { currentCues = cues; - analyticsCollector.onCues(cues); // TODO(internal b/187152483): Events should be dispatched via ListenerSet for (Listener listeners : listenerArraySet) { listeners.onCues(cues); @@ -2807,7 +2800,6 @@ import java.util.concurrent.TimeoutException; @Override public void onMetadata(Metadata metadata) { - analyticsCollector.onMetadata(metadata); ExoPlayerImpl.this.onMetadata(metadata); // TODO(internal b/187152483): Events should be dispatched via ListenerSet for (Listener listener : listenerArraySet) { @@ -2905,7 +2897,6 @@ import java.util.concurrent.TimeoutException; DeviceInfo deviceInfo = createDeviceInfo(streamVolumeManager); if (!deviceInfo.equals(ExoPlayerImpl.this.deviceInfo)) { ExoPlayerImpl.this.deviceInfo = deviceInfo; - analyticsCollector.onDeviceInfoChanged(deviceInfo); // TODO(internal b/187152483): Events should be dispatched via ListenerSet for (Listener listener : listenerArraySet) { listener.onDeviceInfoChanged(deviceInfo); @@ -2915,7 +2906,6 @@ import java.util.concurrent.TimeoutException; @Override public void onStreamVolumeChanged(int streamVolume, boolean streamMuted) { - analyticsCollector.onDeviceVolumeChanged(streamVolume, streamMuted); // TODO(internal b/187152483): Events should be dispatched via ListenerSet for (Listener listener : listenerArraySet) { listener.onDeviceVolumeChanged(streamVolume, streamMuted);