fix: flush BufferedStreamer ring buffer on seek to prevent stale audio
When seeking, the underlying decoder position was updated but the BufferedStreamer's ring buffer still contained up to 2 seconds of pre-seek audio data. The speaker would drain this stale buffer before playing audio from the new position, causing an audible delay where the old position's audio continued playing. Add a Flush() method to BufferedStreamer that resets the ring buffer pointers, and call it in seekLocked() immediately after a successful seek. This ensures the speaker starts playing from the seeked position without any stale audio artifact.
This commit is contained in:
@@ -177,6 +177,19 @@ func (bs *BufferedStreamer) Err() error {
|
||||
return bs.err
|
||||
}
|
||||
|
||||
// Flush discards all buffered samples so the next Stream call
|
||||
// returns freshly-read data from the source. This must be called
|
||||
// after seeking the underlying source to prevent stale pre-seek
|
||||
// audio from being played back.
|
||||
func (bs *BufferedStreamer) Flush() {
|
||||
bs.mu.Lock()
|
||||
defer bs.mu.Unlock()
|
||||
|
||||
bs.readPos = 0
|
||||
bs.writPos = 0
|
||||
bs.count = 0
|
||||
}
|
||||
|
||||
// Close signals the read-ahead goroutine to stop. It is safe to
|
||||
// call multiple times.
|
||||
func (bs *BufferedStreamer) Close() {
|
||||
|
||||
Reference in New Issue
Block a user