fix track restarting on shuffle

This commit is contained in:
Siiiiinth
2026-02-20 16:16:52 +01:00
parent 91701902e6
commit 294be9a0a3
+10 -1
View File
@@ -371,7 +371,16 @@ func (p *playbackEngine) SetShuffle(shuffle bool) {
newNowPlayingIdx := 0
if shuffle {
p.LoadItemsAndPlayAtIdx(p.playQueue, true, p.nowPlayingIdx)
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
}
} else {
if p.nowPlayingIdx >= 0 && len(p.getShuffledPlayQueue()) > p.nowPlayingIdx {
nowPlayingID := p.getShuffledPlayQueue()[p.nowPlayingIdx].Metadata().ID