From 201d120e38a2b1ed5afa2104cd279028d1ecd8b8 Mon Sep 17 00:00:00 2001 From: krocard Date: Mon, 21 Sep 2020 16:38:19 +0100 Subject: [PATCH] Recover from audio server crash while sleeping for offload Without this patch, playback would be frozen indefinitely until the user manually pauses and unpauses it. This has the side effect of disabling offload until the next stop due to the workaround of disabling offload when it encounters a failure. As an audio server crash is considered very infrequent, especially in stable conditions like an audio only playback, it is unlikely that disabling offload is an issue. PiperOrigin-RevId: 332857094 --- .../android/exoplayer2/audio/DefaultAudioSink.java | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 1e04b1e8d7..41e76440c1 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 @@ -28,6 +28,7 @@ import android.os.Handler; import android.os.SystemClock; import android.util.Pair; import androidx.annotation.IntDef; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import com.google.android.exoplayer2.C; @@ -1694,6 +1695,16 @@ public final class DefaultAudioSink implements AudioSink { } } + @Override + public void onTearDown(@NonNull AudioTrack track) { + if (listener != null && playing) { + // A new Audio Track needs to be created and it's buffer filled, which will be done on the + // next handleBuffer call. + // Request this call explicitly in case ExoPlayer is sleeping waiting for a data request. + listener.onOffloadBufferEmptying(); + } + } + public void register(AudioTrack audioTrack) { audioTrack.registerStreamEventCallback(handler::post, this); }