add stop after current check to pop up queue

This commit is contained in:
Drew Weymouth
2025-08-08 08:10:20 -07:00
parent 766cfdfe91
commit d6ad0de122
3 changed files with 30 additions and 2 deletions
+13 -1
View File
@@ -65,6 +65,8 @@ type playbackEngine struct {
isRadio bool
loopMode LoopMode
stopAfterCurrent bool // flag to stop playback after current track ends
// flags for handleOnTrackChange / handleOnStopped callbacks - reset to false in the callbacks
wasStopped bool // true iff player was stopped before handleOnTrackChange invocation
alreadyScrobbled bool // true iff the previously-playing track was already scrobbled
@@ -334,6 +336,15 @@ func (p *playbackEngine) Stop() error {
return p.player.Stop(false)
}
func (p *playbackEngine) SetStopAfterCurrent(stopAfterCurrent bool) {
p.stopAfterCurrent = stopAfterCurrent
if p.stopAfterCurrent {
p.setNextTrack(-1) // clear next playing track from internal player, if any
} else if p.loopMode != LoopNone || p.nowPlayingIdx < len(p.playQueue)-1 {
p.needToSetNextTrack = true // need to restore next track to internal player queue
}
}
func (p *playbackEngine) Pause() error {
return p.player.Pause()
}
@@ -634,6 +645,7 @@ func (p *playbackEngine) handleOnStopped() {
p.alreadyScrobbled = false
p.wasStopped = true
p.nowPlayingIdx = -1
p.stopAfterCurrent = false
}
// to be invoked as soon as the next item in the queue that should play changes
@@ -855,7 +867,7 @@ func (p *playbackEngine) handleTimePosUpdate(seeked bool) {
meta = np.Metadata()
}
isNearEnd := meta.Type != mediaprovider.MediaItemTypeRadioStation && s.TimePos > meta.Duration.Seconds()-10
if p.needToSetNextTrack && isNearEnd {
if p.needToSetNextTrack && !p.stopAfterCurrent && isNearEnd {
p.needToSetNextTrack = false
p.setNextTrack(p.nextPlayingIndex())
}
+8
View File
@@ -669,6 +669,14 @@ func (p *PlaybackManager) PlayPause() {
}
}
func (p *PlaybackManager) SetStopAfterCurrent(stopAfterCurrent bool) {
p.engine.SetStopAfterCurrent(stopAfterCurrent)
}
func (p *PlaybackManager) IsStopAfterCurrent() bool {
return p.engine.stopAfterCurrent
}
func (p *PlaybackManager) enqueueAutoplayTracks() {
nowPlaying := p.NowPlaying()
if nowPlaying == nil {