From 60913cdfa151714907dc39b45cb044cc24c15301 Mon Sep 17 00:00:00 2001 From: bloeys Date: Sat, 25 Jun 2022 22:58:23 +0400 Subject: [PATCH] Reset before seek --- wavy.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wavy.go b/wavy.go index f291265..60bb7f6 100644 --- a/wavy.go +++ b/wavy.go @@ -91,9 +91,6 @@ func (s *Sound) PlaySync() { for s.Player.IsPlaying() || s.Player.UnplayedBufferSize() > 0 { time.Sleep(time.Millisecond) } - - //This is needed to ensure things work when we try to reuse (e.g. playSync->seek->play) - s.Player.Reset() } //TotalTime returns the time taken to play the entire sound. @@ -143,6 +140,10 @@ func (s *Sound) IsPlaying() bool { //percent is clamped [0,1], so passing <0 is the same as zero, and >1 is the same as 1 func (s *Sound) SeekToPercent(percent float64) { + if !s.IsPlaying() { + s.Player.Reset() + } + if percent < 0 { percent = 0 } else if percent > 1 { @@ -154,6 +155,10 @@ func (s *Sound) SeekToPercent(percent float64) { func (s *Sound) SeekToTime(t time.Duration) { + if !s.IsPlaying() { + s.Player.Reset() + } + byteCount := ByteCountFromPlayTime(t) if byteCount < 0 { byteCount = 0