fixed playTrackAt when double clicking track

This commit is contained in:
Siiiiinth
2026-02-20 15:57:54 +01:00
parent 194e15cff6
commit 91701902e6
4 changed files with 54 additions and 12 deletions
+27 -10
View File
@@ -371,16 +371,7 @@ func (p *playbackEngine) SetShuffle(shuffle bool) {
newNowPlayingIdx := 0
if shuffle {
shuffledQueue := deepCopyMediaItemSlice(p.playQueue)
rand.Shuffle(len(shuffledQueue), func(i, j int) {
shuffledQueue[i], shuffledQueue[j] = shuffledQueue[j], shuffledQueue[i]
})
if p.nowPlayingIdx >= 0 && len(p.getPlayQueue()) > p.nowPlayingIdx {
nowPlayingID := p.getPlayQueue()[p.nowPlayingIdx].Metadata().ID
p.setShuffledPlayQueue(sharedutil.ReorderItems(shuffledQueue, []int{p.GetTrackIdxByIdFrom(shuffledQueue, nowPlayingID)}, 0))
} else {
return
}
p.LoadItemsAndPlayAtIdx(p.playQueue, true, p.nowPlayingIdx)
} else {
if p.nowPlayingIdx >= 0 && len(p.getShuffledPlayQueue()) > p.nowPlayingIdx {
nowPlayingID := p.getShuffledPlayQueue()[p.nowPlayingIdx].Metadata().ID
@@ -515,6 +506,32 @@ func (p *playbackEngine) LoadItems(items []mediaprovider.MediaItem, insertQueueM
return p.doLoaditems(newItems, insertQueueMode, shuffle)
}
// Load items into the play queue.
// If replacing the current queue (!appendToQueue), playback will be stopped.
func (p *playbackEngine) LoadItemsAndPlayAtIdx(items []mediaprovider.MediaItem, shuffle bool, idx int) error {
newItems := deepCopyMediaItemSlice(items)
if p.shuffle || shuffle {
rand.Shuffle(len(newItems), func(i, j int) {
newItems[i], newItems[j] = newItems[j], newItems[i]
})
if idx < len(items) {
nowPlayingID := items[idx].Metadata().ID
p.setPlayQueue(deepCopyMediaItemSlice(items))
p.setShuffledPlayQueue(sharedutil.ReorderItems(newItems, []int{p.GetTrackIdxByIdFrom(newItems, nowPlayingID)}, 0))
p.PlayTrackAt(0)
}
} else {
p.doLoaditems(newItems, Replace, shuffle)
p.PlayTrackAt(idx)
}
p.handleNextTrackUpdated()
p.invokeNoArgCallbacks(p.onQueueChange)
return nil
}
// Load tracks into the play queue.
// If replacing the current queue (!appendToQueue), playback will be stopped.
func (p *playbackEngine) LoadTracks(tracks []*mediaprovider.Track, insertQueueMode InsertQueueMode, shuffle bool) error {