Commit 3c9b0b9b by bachinger Committed by Ian Baker

Do not setOffloadEndOfStream if AudioTrack is not playing

AudioTrack.setOffloadEndOfStream should be called after a track
has been buffered. Additionally, the AudioTrack must be playing.

It has been observed that for very short media (<1s), the AudioTrack
might not have started immediately after the read that buffered
the audio.

In such a situation, calling AudioTrack.setOffloadEndOfStream throws
and playback fails.

Avoid this failure by checking that the AudioTrack is playing before
calling setOffloadEndOfStream.

This means that very short gapless media will not be gapless, this was
deemed acceptable given that such very short media should be very rare
in offload.

PiperOrigin-RevId: 450431146
parent 96f35bbc
...@@ -905,7 +905,11 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -905,7 +905,11 @@ public final class DefaultAudioSink implements AudioSink {
pendingConfiguration = null; pendingConfiguration = null;
if (isOffloadedPlayback(audioTrack) if (isOffloadedPlayback(audioTrack)
&& offloadMode != OFFLOAD_MODE_ENABLED_GAPLESS_DISABLED) { && offloadMode != OFFLOAD_MODE_ENABLED_GAPLESS_DISABLED) {
audioTrack.setOffloadEndOfStream(); // If the first track is very short (typically <1s), the offload AudioTrack might
// not have started yet. Do not call setOffloadEndOfStream as it would throw.
if (audioTrack.getPlayState() == AudioTrack.PLAYSTATE_PLAYING) {
audioTrack.setOffloadEndOfStream();
}
audioTrack.setOffloadDelayPadding( audioTrack.setOffloadDelayPadding(
configuration.inputFormat.encoderDelay, configuration.inputFormat.encoderPadding); configuration.inputFormat.encoderDelay, configuration.inputFormat.encoderPadding);
isWaitingForOffloadEndOfStreamHandled = true; isWaitingForOffloadEndOfStreamHandled = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment