Fix first song not being shuffled
This commit is contained in:
parent
7dbbd77c4e
commit
c5409a8d8b
|
@ -115,6 +115,9 @@ func FindServiceAndAdd(user *gumble.User, url string) error {
|
|||
|
||||
// Starts playing the new song if nothing else is playing
|
||||
if oldLength == 0 && dj.queue.Len() != 0 && !dj.audioStream.IsPlaying() {
|
||||
if (dj.conf.General.AutomaticShuffleOn){
|
||||
dj.queue.RandomNextSong(true)
|
||||
}
|
||||
if err := dj.queue.CurrentSong().Download(); err == nil {
|
||||
dj.queue.CurrentSong().Play()
|
||||
} else {
|
||||
|
|
16
songqueue.go
16
songqueue.go
|
@ -64,9 +64,8 @@ func (q *SongQueue) NextSong() {
|
|||
// PeekNext peeks at the next Song and returns it.
|
||||
func (q *SongQueue) PeekNext() (Song, error) {
|
||||
if q.Len() > 1 {
|
||||
if (dj.conf.General.AutomaticShuffleOn){ //Shuffle mode is active
|
||||
swapIndex := 1 + rand.Intn(q.Len())
|
||||
q.queue[1], q.queue[swapIndex] = q.queue[swapIndex], q.queue[1]
|
||||
if dj.conf.General.AutomaticShuffleOn{ //Shuffle mode is active
|
||||
q.RandomNextSong(false)
|
||||
}
|
||||
return q.queue[1], nil
|
||||
}
|
||||
|
@ -121,3 +120,14 @@ func (q *SongQueue) ShuffleSongs() {
|
|||
q.queue[i + 1], q.queue[j + 1] = q.queue[j + 1], q.queue[i + 1]
|
||||
}
|
||||
}
|
||||
|
||||
// Sets a random song as next song to be played
|
||||
// queueWasEmpty wether the queue was empty before adding the last Song
|
||||
func (q *SongQueue) RandomNextSong(queueWasEmpty bool){
|
||||
nextSongIndex := 1
|
||||
if queueWasEmpty{
|
||||
nextSongIndex = 0
|
||||
}
|
||||
swapIndex := nextSongIndex + rand.Intn(q.Len())
|
||||
q.queue[nextSongIndex], q.queue[swapIndex] = q.queue[swapIndex], q.queue[nextSongIndex]
|
||||
}
|
||||
|
|
Reference in a new issue