Scrobble playing track when removed from queue
This change fixes two `TODO` comments, by scrobbling the currently playing track if it's removed from the queue, and only run OnSongChange callbacks when the playing track is affected.
This commit is contained in:
@@ -248,11 +248,15 @@ func (p *PlaybackManager) RemoveTracksFromQueue(trackIDs []string) {
|
|||||||
newQueue := make([]*mediaprovider.Track, 0, len(p.playQueue)-len(trackIDs))
|
newQueue := make([]*mediaprovider.Track, 0, len(p.playQueue)-len(trackIDs))
|
||||||
rmCount := 0
|
rmCount := 0
|
||||||
idSet := sharedutil.ToSet(trackIDs)
|
idSet := sharedutil.ToSet(trackIDs)
|
||||||
|
isPlayingTrackRemoved := false
|
||||||
for i, tr := range p.playQueue {
|
for i, tr := range p.playQueue {
|
||||||
if _, ok := idSet[tr.ID]; ok {
|
if _, ok := idSet[tr.ID]; ok {
|
||||||
// removing this track
|
// removing this track
|
||||||
// TODO: if we are removing the currently playing track,
|
if i == p.NowPlayingIndex() {
|
||||||
// we need to scrobble it if it played for more than the scrobble threshold
|
isPlayingTrackRemoved = true
|
||||||
|
// If we are removing the currently playing track, we need to scrobble it
|
||||||
|
p.checkScrobble(p.playTimeStopwatch.Elapsed())
|
||||||
|
}
|
||||||
if err := p.player.RemoveTrackAt(i - rmCount); err == nil {
|
if err := p.player.RemoveTrackAt(i - rmCount); err == nil {
|
||||||
rmCount++
|
rmCount++
|
||||||
} else {
|
} else {
|
||||||
@@ -268,9 +272,10 @@ func (p *PlaybackManager) RemoveTracksFromQueue(trackIDs []string) {
|
|||||||
p.playQueue = newQueue
|
p.playQueue = newQueue
|
||||||
p.nowPlayingIdx = p.player.GetStatus().PlaylistPos
|
p.nowPlayingIdx = p.player.GetStatus().PlaylistPos
|
||||||
// fire on song change callbacks in case the playing track was removed
|
// fire on song change callbacks in case the playing track was removed
|
||||||
// TODO: only call this if the playing track actually was removed
|
if isPlayingTrackRemoved {
|
||||||
p.invokeOnSongChangeCallbacks()
|
p.invokeOnSongChangeCallbacks()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Stop playback and clear the play queue.
|
// Stop playback and clear the play queue.
|
||||||
func (p *PlaybackManager) StopAndClearPlayQueue() {
|
func (p *PlaybackManager) StopAndClearPlayQueue() {
|
||||||
|
|||||||
Reference in New Issue
Block a user