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
This commit is contained in:
tonihei 2022-02-08 16:41:10 +00:00 committed by Ian Baker
parent 1223fa23b0
commit 34a2a6ea18

View File

@ -403,7 +403,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) {
@ -1387,7 +1387,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);
@ -1425,7 +1424,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);
@ -1453,7 +1451,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);
@ -2480,7 +2477,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);
@ -2494,7 +2490,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);
@ -2693,7 +2688,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);
@ -2801,7 +2795,6 @@ import java.util.concurrent.TimeoutException;
@Override
public void onCues(List<Cue> cues) {
currentCues = cues;
analyticsCollector.onCues(cues);
// TODO(internal b/187152483): Events should be dispatched via ListenerSet
for (Listener listeners : listenerArraySet) {
listeners.onCues(cues);
@ -2812,7 +2805,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) {
@ -2910,7 +2902,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);
@ -2920,7 +2911,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);