moved logic to playbackengine, forceRestart preserves pause state

This commit is contained in:
Siiiiinth
2026-01-05 00:25:33 +01:00
parent bc472eb065
commit 81c935fdd0
3 changed files with 16 additions and 9 deletions
+6
View File
@@ -627,6 +627,12 @@ func (p *playbackEngine) handleOnTrackChange() {
p.invokeOnSongChangeCallbacks() p.invokeOnSongChangeCallbacks()
p.handleTimePosUpdate(false) p.handleTimePosUpdate(false)
p.handleNextTrackUpdated() p.handleNextTrackUpdated()
if p.pauseAfterCurrent {
p.Pause()
p.SetPauseAfterCurrent(false)
}
} }
func (p *playbackEngine) handleOnStopped() { func (p *playbackEngine) handleOnStopped() {
+8 -6
View File
@@ -134,11 +134,6 @@ func (p *PlaybackManager) addOnTrackChangeHook() {
log.Println("Play stall detected!") log.Println("Play stall detected!")
p.cmdQueue.addCommand(playbackCommand{Type: cmdForceRestartPlayback}) p.cmdQueue.addCommand(playbackCommand{Type: cmdForceRestartPlayback})
} }
if p.engine.pauseAfterCurrent {
p.Pause()
p.engine.SetPauseAfterCurrent(false)
}
}() }()
} }
}) })
@@ -832,7 +827,14 @@ func (p *PlaybackManager) runCmdQueue(ctx context.Context) {
case cmdForceRestartPlayback: case cmdForceRestartPlayback:
if mpv, ok := p.engine.CurrentPlayer().(*mpv.Player); ok { if mpv, ok := p.engine.CurrentPlayer().(*mpv.Player); ok {
log.Println("Force-restarting MPV playback") log.Println("Force-restarting MPV playback")
mpv.ForceRestartPlayback()
// restart player, but perserve the state
isPaused := false
stat := p.engine.CurrentPlayer().GetStatus()
if stat.State == player.Paused {
isPaused = true
}
mpv.ForceRestartPlayback(isPaused)
} }
} }
if c.OnDone != nil { if c.OnDone != nil {
+2 -3
View File
@@ -349,9 +349,8 @@ func (p *Player) Continue() error {
return nil return nil
} }
func (p *Player) ForceRestartPlayback() error { func (p *Player) ForceRestartPlayback(isPaused bool) error {
p.mpv.SetProperty("pause", mpv.FORMAT_FLAG, true) return p.mpv.SetProperty("pause", mpv.FORMAT_FLAG, isPaused)
return p.mpv.SetProperty("pause", mpv.FORMAT_FLAG, false)
} }
// Get the current status of the player. // Get the current status of the player.