From aec6fe7e655c08c125589d080f1428806afc66fe Mon Sep 17 00:00:00 2001 From: kimvde Date: Mon, 16 Mar 2020 17:31:04 +0000 Subject: [PATCH] Notify listeners when audio session ID is set PiperOrigin-RevId: 301187369 --- .../android/exoplayer2/SimpleExoPlayer.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java index cf29480a3c..9861c324ab 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/SimpleExoPlayer.java @@ -698,6 +698,9 @@ public class SimpleExoPlayer extends BasePlayer @Override public void setAudioSessionId(int audioSessionId) { verifyApplicationThread(); + if (this.audioSessionId == audioSessionId) { + return; + } this.audioSessionId = audioSessionId; for (Renderer renderer : renderers) { if (renderer.getTrackType() == C.TRACK_TYPE_AUDIO) { @@ -708,6 +711,9 @@ public class SimpleExoPlayer extends BasePlayer .send(); } } + if (audioSessionId != C.AUDIO_SESSION_ID_UNSET) { + notifyAudioSessionIdSet(); + } } @Override @@ -1816,6 +1822,19 @@ public class SimpleExoPlayer extends BasePlayer } } + private void notifyAudioSessionIdSet() { + for (AudioListener audioListener : audioListeners) { + // Prevent duplicate notification if a listener is both a AudioRendererEventListener and + // a AudioListener, as they have the same method signature. + if (!audioDebugListeners.contains(audioListener)) { + audioListener.onAudioSessionId(audioSessionId); + } + } + for (AudioRendererEventListener audioDebugListener : audioDebugListeners) { + audioDebugListener.onAudioSessionId(audioSessionId); + } + } + @SuppressWarnings("SuspiciousMethodCalls") private void notifySkipSilenceEnabledChanged() { for (AudioListener listener : audioListeners) { @@ -1986,16 +2005,7 @@ public class SimpleExoPlayer extends BasePlayer return; } audioSessionId = sessionId; - for (AudioListener audioListener : audioListeners) { - // Prevent duplicate notification if a listener is both a AudioRendererEventListener and - // a AudioListener, as they have the same method signature. - if (!audioDebugListeners.contains(audioListener)) { - audioListener.onAudioSessionId(sessionId); - } - } - for (AudioRendererEventListener audioDebugListener : audioDebugListeners) { - audioDebugListener.onAudioSessionId(sessionId); - } + notifyAudioSessionIdSet(); } @Override