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
This commit is contained in:
krocard 2020-09-21 16:38:19 +01:00 committed by Oliver Woodman
parent 1850a918f1
commit 201d120e38

View File

@ -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);
}