From caeaa9574e5f3841425d970ee6cf564bed1ec9dd Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Sat, 23 Feb 2019 20:20:10 +0000 Subject: [PATCH] Avoid draining audio processors while reset If the DefaultAudioSink was reconfigured in a way that was compatible with the previous configuration just after having been reset, we would try to drain audio processors despite not having an AudioTrack. This could result in a NullPointerException if speed adjustment was active. Fix this behavior by only trying to drain audio processors if we actually have an AudioTrack. PiperOrigin-RevId: 235355466 --- .../exoplayer2/audio/DefaultAudioSink.java | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java index 12087382ef..f1c64e904c 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/DefaultAudioSink.java @@ -465,14 +465,17 @@ public final class DefaultAudioSink implements AudioSink { processingEnabled, canApplyPlaybackParameters, availableAudioProcessors); - if (configuration == null || !pendingConfiguration.canReuseAudioTrack(configuration)) { - // We need a new AudioTrack before we can handle more input. We should first stop() the track - // (if we have one) and wait for audio to play out. Tracked by [Internal: b/33161961]. - flush(); - } else if (flushAudioProcessors) { - // We don't need a new AudioTrack but audio processors need to be flushed. - this.pendingConfiguration = pendingConfiguration; - return; + if (isInitialized()) { + if (!pendingConfiguration.canReuseAudioTrack(configuration)) { + // We need a new AudioTrack before we can handle more input. We should first stop() the + // track and wait for audio to play out (tracked by [Internal: b/33161961]), but for now we + // discard the audio track immediately. + flush(); + } else if (flushAudioProcessors) { + // We don't need a new AudioTrack but audio processors need to be drained and flushed. + this.pendingConfiguration = pendingConfiguration; + return; + } } configuration = pendingConfiguration; }