shuffle func checkpoint 2
This commit is contained in:
@@ -238,7 +238,11 @@ 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 {
|
||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user