mirror of
https://github.com/bloeys/wavy.git
synced 2025-12-29 09:28:19 +00:00
Reset before seek
This commit is contained in:
11
wavy.go
11
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
|
||||
|
||||
Reference in New Issue
Block a user