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
This commit is contained in:
parent
d6a6529b06
commit
a8a4faa28c
@ -914,7 +914,11 @@ public final class DefaultAudioSink implements AudioSink {
|
||||
pendingConfiguration = null;
|
||||
if (isOffloadedPlayback(audioTrack)
|
||||
&& 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(
|
||||
configuration.inputFormat.encoderDelay, configuration.inputFormat.encoderPadding);
|
||||
isWaitingForOffloadEndOfStreamHandled = true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user