From fdce6abf2796f6ecb6e637c36c33805315d1b51e 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 c8f95c557f..e5d0b28c75 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 @@ -393,7 +393,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) { @@ -1377,7 +1377,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); @@ -1415,7 +1414,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); @@ -1443,7 +1441,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); @@ -2470,7 +2467,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); @@ -2484,7 +2480,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); @@ -2683,7 +2678,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); @@ -2791,7 +2785,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); @@ -2802,7 +2795,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) { @@ -2900,7 +2892,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); @@ -2910,7 +2901,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);