shuffle func checkpoint 2

This commit is contained in:
Siiiiinth
2026-02-15 09:28:38 -08:00
committed by Drew Weymouth
parent 452ac8ff5b
commit 177c43655d
+54 -7
View File
@@ -238,8 +238,12 @@ func (p *playbackEngine) clearPlayQueue() {
} }
func (p *playbackEngine) setPlayQueue(items []mediaprovider.MediaItem) { func (p *playbackEngine) setPlayQueue(items []mediaprovider.MediaItem) {
if p.shuffle {
p.shuffledPlayQueue = items
} else {
p.playQueue = items p.playQueue = items
} }
}
func (p *playbackEngine) getPlayQueueItemAt(idx int) mediaprovider.MediaItem { func (p *playbackEngine) getPlayQueueItemAt(idx int) mediaprovider.MediaItem {
return p.getPlayQueue()[idx] return p.getPlayQueue()[idx]
@@ -307,16 +311,59 @@ func (p *playbackEngine) SetShuffle(shuffle bool) {
} }
if shuffle { if shuffle {
fmt.Println("shuffling") fmt.Println("shuffling")
items := deepCopyMediaItemSlice(p.playQueue) newQueue := deepCopyMediaItemSlice(p.playQueue)
rand.Shuffle(len(items), func(i, j int) { rand.Shuffle(len(newQueue), func(i, j int) {
items[i], items[j] = items[j], items[i] newQueue[i], newQueue[j] = newQueue[j], newQueue[i]
}) })
p.UpdatePlayQueue(items) fmt.Println(p.playQueue[0].Metadata().ID)
} else { newNowPlayingIdx := -1
fmt.Println("deshuffling") if p.nowPlayingIdx >= 0 {
p.UpdatePlayQueue(p.playQueue) nowPlayingID := p.getPlayQueueItemAt(p.nowPlayingIdx).Metadata().ID
for i, tr := range newQueue {
if tr.Metadata().ID == nowPlayingID {
newNowPlayingIdx = i
break
}
}
} }
p.shuffle = shuffle p.shuffle = shuffle
p.setPlayQueue(newQueue)
if p.nowPlayingIdx >= 0 && newNowPlayingIdx == -1 {
return
}
if p.nowPlayingIdx >= 0 {
p.handleNextTrackUpdated()
}
p.nowPlayingIdx = newNowPlayingIdx
p.invokeNoArgCallbacks(p.onQueueChange)
} else {
fmt.Println("deshuffling")
fmt.Println(p.playQueue[0].Metadata().ID)
newQueue := deepCopyMediaItemSlice(p.playQueue)
newNowPlayingIdx := -1
if p.nowPlayingIdx >= 0 {
nowPlayingID := p.getPlayQueueItemAt(p.nowPlayingIdx).Metadata().ID
for i, tr := range newQueue {
if tr.Metadata().ID == nowPlayingID {
newNowPlayingIdx = i
break
}
}
}
p.shuffle = shuffle
p.setPlayQueue(newQueue)
if p.nowPlayingIdx >= 0 && newNowPlayingIdx == -1 {
return
}
if p.nowPlayingIdx >= 0 {
p.handleNextTrackUpdated()
}
p.nowPlayingIdx = newNowPlayingIdx
p.invokeNoArgCallbacks(p.onQueueChange)
}
} }
func (p *playbackEngine) GetShuffle() bool { func (p *playbackEngine) GetShuffle() bool {