From b94e70bdd6a5728464c30ad1a845646ab22b39ce Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Fri, 20 Dec 2024 16:16:33 +0500 Subject: [PATCH] Fix load queue seeking * Add method for mpvplayer to check if the player is allowed to seek * Make the load queue functionality seek to the saved position when mpv is ready to seek --- mpvplayer/player.go | 5 +++++ page_queue.go | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mpvplayer/player.go b/mpvplayer/player.go index febe14e..d85cd03 100644 --- a/mpvplayer/player.go +++ b/mpvplayer/player.go @@ -151,6 +151,11 @@ func (p *Player) IsSongLoaded() (bool, error) { return !idle, err } +func (p *Player) IsSeekable() (bool, error) { + seekable, err := p.getPropertyBool("seekable") + return seekable, err +} + func (p *Player) IsPaused() (bool, error) { pause, err := p.getPropertyBool("pause") return pause, err diff --git a/page_queue.go b/page_queue.go index 500dcea..d1326ce 100644 --- a/page_queue.go +++ b/page_queue.go @@ -127,10 +127,16 @@ func (ui *Ui) createQueuePage() *QueuePage { if err := ui.player.Play(); err != nil { queuePage.logger.Printf("error playing: %s", err) } + _ = ui.player.Pause() + for { + if seekable, err := ui.player.IsSeekable(); err == nil && seekable { + break + } + time.Sleep(100 * time.Millisecond) + } if err = ui.player.Seek(ssr.PlayQueue.Position); err != nil { queuePage.logger.Printf("unable to seek to position %s: %s", time.Duration(ssr.PlayQueue.Position)*time.Second, err) } - _ = ui.player.Pause() } }()