From 29099cf66020a6a799688e6206708e3cc573db97 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 21 Feb 2021 23:54:43 +0900 Subject: [PATCH] audio: Bug fix: Continue to play the audio after seeking on go2cpp --- audio/internal/go2cpp/player_js.go | 2 ++ audio/readerplayer.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/audio/internal/go2cpp/player_js.go b/audio/internal/go2cpp/player_js.go index 615fcaa0e..e2df9b34e 100644 --- a/audio/internal/go2cpp/player_js.go +++ b/audio/internal/go2cpp/player_js.go @@ -149,6 +149,8 @@ func (p *Player) Reset() { if p.state == playerStateClosed { return } + p.state = playerStatePaused + if !p.v.Truthy() { return } diff --git a/audio/readerplayer.go b/audio/readerplayer.go index a7a26242d..ae0264aa2 100644 --- a/audio/readerplayer.go +++ b/audio/readerplayer.go @@ -117,6 +117,7 @@ func (p *readerPlayer) Current() time.Duration { defer p.m.Unlock() // TODO: Add a new function to readerDriverPlayer and use it. + // src's position doesn't reflect the exact playing position. return p.src.Current() } @@ -128,6 +129,11 @@ func (p *readerPlayer) Seek(offset time.Duration) error { p.m.Lock() defer p.m.Unlock() + if p.player.IsPlaying() { + defer func() { + p.player.Play() + }() + } p.player.Reset() return p.src.Seek(offset) }