Skip to content

fix: flush AudioTrack on pause so audio stops immediately#52

Merged
chrisuthe merged 1 commit intomainfrom
task/fix-pause-audio-drain
Mar 7, 2026
Merged

fix: flush AudioTrack on pause so audio stops immediately#52
chrisuthe merged 1 commit intomainfrom
task/fix-pause-audio-drain

Conversation

@chrisuthe
Copy link
Copy Markdown
Owner

Summary

Fixes a bug where pressing pause doesn't immediately stop audio output -- audio continues playing for up to ~1 second while the AudioTrack hardware buffer drains.

Root cause: SyncAudioPlayer.pause() called audioTrack.pause() without audioTrack.flush(). The pause() API stops the AudioTrack from reading new data from its ring buffer, but any audio already queued in the hardware buffer (~1 second at 48kHz) continues playing through the DAC.

Fix: Add audioTrack.flush() after audioTrack.pause(). This clears the hardware buffer so audio stops immediately. The chunk-level queue is preserved for seamless resume -- resume() already resets DAC calibrations and sync state, and the playback loop refills the AudioTrack from the chunk queue.

Test plan

  • New PauseFlushTest validates pause/flush/resume ordering
  • All existing unit tests pass
  • Manual test: play audio, press pause -- audio should stop immediately (no ~1s tail)
  • Manual test: pause then resume -- playback should resume smoothly
  • Manual test: pause for >5 seconds then resume -- buffer should clear and refill from server

Previously, pause() called audioTrack.pause() without flush(), leaving
up to ~1 second of audio draining through the hardware DAC buffer. Now
pause() also calls flush() to clear the hardware buffer. The chunk-level
queue is preserved for seamless resume.
@chrisuthe chrisuthe merged commit 6c869eb into main Mar 7, 2026
@chrisuthe chrisuthe deleted the task/fix-pause-audio-drain branch March 8, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant