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:
@@ -818,6 +818,13 @@ func (p *Player) seekLocked(targetSeconds int) error {
|
||||
|
||||
speaker.Unlock()
|
||||
|
||||
// Flush the read-ahead buffer so the speaker immediately
|
||||
// plays audio from the new position instead of draining
|
||||
// up to 2 seconds of stale pre-seek samples.
|
||||
if p.buffered != nil {
|
||||
p.buffered.Flush()
|
||||
}
|
||||
|
||||
if p.mediaControls != nil {
|
||||
p.mediaControls.NotifySeek(targetSeconds)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user