Skip to content

Commit 3f03852

Browse files
toniheicopybara-github
authored andcommitted
Avoid calling audioTrack.play() on stopped AudioTrack
We already avoid calling pause() because it has no effect once the AudioTrack is stopped. But still call play(), leaving the platform AudioTrack in a strange perpetual playing state that does not match our internal state tracking. Also simplify the flow a bit by letting DefaultAudioSink decide that by itself without going via return values from AudioTrackPositionTracker. PiperOrigin-RevId: 784190418
1 parent 5e0dc3e commit 3f03852

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/audio/AudioTrackPositionTracker.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -450,22 +450,15 @@ public boolean hasPendingData(long writtenFrames) {
450450
|| forceHasPendingData();
451451
}
452452

453-
/**
454-
* Pauses the audio track position tracker, returning whether the audio track needs to be paused
455-
* to cause playback to pause. If {@code false} is returned the audio track will pause without
456-
* further interaction, as the end of stream has been handled.
457-
*/
458-
public boolean pause() {
453+
/** Pauses the audio track position tracker. */
454+
public void pause() {
459455
resetSyncParams();
460456
if (stopTimestampUs == C.TIME_UNSET) {
461457
// The audio track is going to be paused, so reset the timestamp poller to ensure it doesn't
462458
// supply an advancing position.
463459
checkNotNull(audioTimestampPoller).reset();
464-
return true;
465460
}
466461
stopPlaybackHeadPosition = getPlaybackHeadPosition();
467-
// We've handled the end of the stream already, so there's no need to pause the track.
468-
return false;
469462
}
470463

471464
/**

libraries/exoplayer/src/main/java/androidx/media3/exoplayer/audio/DefaultAudioSink.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,9 @@ public void play() {
935935
playing = true;
936936
if (isAudioTrackInitialized()) {
937937
audioTrackPositionTracker.start();
938-
audioTrack.play();
938+
if (!stoppedAudioTrack || isOffloadedPlayback(audioTrack)) {
939+
audioTrack.play();
940+
}
939941
}
940942
}
941943

@@ -1599,9 +1601,11 @@ private void setVolumeInternal() {
15991601
@Override
16001602
public void pause() {
16011603
playing = false;
1602-
if (isAudioTrackInitialized()
1603-
&& (audioTrackPositionTracker.pause() || isOffloadedPlayback(audioTrack))) {
1604-
audioTrack.pause();
1604+
if (isAudioTrackInitialized()) {
1605+
audioTrackPositionTracker.pause();
1606+
if (!stoppedAudioTrack || isOffloadedPlayback(audioTrack)) {
1607+
audioTrack.pause();
1608+
}
16051609
}
16061610
}
16071611

0 commit comments

Comments
 (0)