fix tracklist selection being maintained when sorting

This commit is contained in:
Drew Weymouth
2023-06-02 17:43:22 -07:00
parent 8b238fd239
commit b64dcdcc0b
5 changed files with 182 additions and 71 deletions
+4 -5
View File
@@ -241,16 +241,15 @@ func (p *PlaybackManager) OnTrackRatingChanged(id string, rating int) {
}
// trackIdxs must be sorted
func (p *PlaybackManager) RemoveTracksFromQueue(trackIdxs []int) {
newQueue := make([]*mediaprovider.Track, 0, len(p.playQueue)-len(trackIdxs))
func (p *PlaybackManager) RemoveTracksFromQueue(trackIDs []string) {
newQueue := make([]*mediaprovider.Track, 0, len(p.playQueue)-len(trackIDs))
rmCount := 0
rmIdx := 0
idSet := sharedutil.ToSet(trackIDs)
for i, tr := range p.playQueue {
if rmIdx < len(trackIdxs) && trackIdxs[rmIdx] == i {
if _, ok := idSet[tr.ID]; ok {
// removing this track
// TODO: if we are removing the currently playing track,
// we need to scrobble it if it played for more than the scrobble threshold
rmIdx++
if err := p.player.RemoveTrackAt(i - rmCount); err == nil {
rmCount++
} else {