From 793b570999bf4948a161bc5aa4cbe6c6d2b1abe4 Mon Sep 17 00:00:00 2001 From: Drew Weymouth Date: Sun, 7 Jan 2024 17:14:57 -0800 Subject: [PATCH] load saved play position on startup --- backend/app.go | 16 +++++++++++++++- ui/mainwindow.go | 8 +++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/backend/app.go b/backend/app.go index d98fbf7..f57d3fd 100644 --- a/backend/app.go +++ b/backend/app.go @@ -317,7 +317,21 @@ func (a *App) LoadSavedPlayQueue() error { if err != nil { return err } - return a.PlaybackManager.LoadTracks(queue.Tracks, false, false) + if len(queue.Tracks) == 0 { + return nil + } + + if err := a.PlaybackManager.LoadTracks(queue.Tracks, false, false); err != nil { + return err + } + if queue.TrackIndex >= 0 { + // TODO: This isn't ideal but doesn't seem to cause an audible play-for-a-split-second artifact + a.PlaybackManager.PlayTrackAt(queue.TrackIndex) + a.PlaybackManager.Pause() + time.Sleep(50 * time.Millisecond) // MPV seek fails if run immediately after + a.PlaybackManager.SeekSeconds(queue.TimePos) + } + return nil } func (a *App) SaveConfigFile() { diff --git a/ui/mainwindow.go b/ui/mainwindow.go index 7781f67..54d6797 100644 --- a/ui/mainwindow.go +++ b/ui/mainwindow.go @@ -142,9 +142,11 @@ func (m *MainWindow) RunOnServerConnectedTasks(app *backend.App, displayAppName m.BottomPanel.NowPlaying.DisableRating = !canRate if app.Config.Application.SavePlayQueue { - if err := app.LoadSavedPlayQueue(); err != nil { - log.Printf("failed to load saved play queue: %s", err.Error()) - } + go func() { + if err := app.LoadSavedPlayQueue(); err != nil { + log.Printf("failed to load saved play queue: %s", err.Error()) + } + }() } // check if launching new version, else if found available update on startup