moved logic to playbackengine, forceRestart preserves pause state
This commit is contained in:
@@ -627,6 +627,12 @@ func (p *playbackEngine) handleOnTrackChange() {
|
||||
p.invokeOnSongChangeCallbacks()
|
||||
p.handleTimePosUpdate(false)
|
||||
p.handleNextTrackUpdated()
|
||||
|
||||
if p.pauseAfterCurrent {
|
||||
p.Pause()
|
||||
p.SetPauseAfterCurrent(false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (p *playbackEngine) handleOnStopped() {
|
||||
|
||||
@@ -134,11 +134,6 @@ func (p *PlaybackManager) addOnTrackChangeHook() {
|
||||
log.Println("Play stall detected!")
|
||||
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:
|
||||
if mpv, ok := p.engine.CurrentPlayer().(*mpv.Player); ok {
|
||||
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 {
|
||||
|
||||
@@ -349,9 +349,8 @@ func (p *Player) Continue() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Player) ForceRestartPlayback() error {
|
||||
p.mpv.SetProperty("pause", mpv.FORMAT_FLAG, true)
|
||||
return p.mpv.SetProperty("pause", mpv.FORMAT_FLAG, false)
|
||||
func (p *Player) ForceRestartPlayback(isPaused bool) error {
|
||||
return p.mpv.SetProperty("pause", mpv.FORMAT_FLAG, isPaused)
|
||||
}
|
||||
|
||||
// Get the current status of the player.
|
||||
|
||||
Reference in New Issue
Block a user