Skip to content

Commit

Permalink
Fix load queue seeking
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
mahmed2000 committed Dec 20, 2024
1 parent 4a8428b commit b94e70b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions mpvplayer/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion page_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}()

Expand Down

0 comments on commit b94e70b

Please sign in to comment.