Fixed reset on non-empty queue

Fixed an issue where reset didn't work when the queue had any tracks in
it. The issue stemmed from the fact that in the last few lines of the
PlayCurrent method in the queue.go, around line 314, it sets up another
thread to wait and eventually skip the current track. When reset is
called this skip is triggered on an empty queue which causes an error.
Fixed it by adding a check around the offending lines.
This commit is contained in:
Jason Waataja 2018-07-20 17:19:19 -07:00
parent a57c3f579d
commit 6e76c79e0a

View file

@ -211,22 +211,24 @@ func (q *Queue) Skip() {
}
// Remove all playlist skips if this is the last track of the playlist still in the queue.
if playlist := q.Queue[0].GetPlaylist(); playlist != nil {
id := playlist.GetID()
playlistIsFinished := true
if len(q.Queue) > 0 {
if playlist := q.Queue[0].GetPlaylist(); playlist != nil {
id := playlist.GetID()
playlistIsFinished := true
q.mutex.Unlock()
q.Traverse(func(i int, t interfaces.Track) {
if i != 0 && t.GetPlaylist() != nil {
if t.GetPlaylist().GetID() == id {
playlistIsFinished = false
q.mutex.Unlock()
q.Traverse(func(i int, t interfaces.Track) {
if i != 0 && t.GetPlaylist() != nil {
if t.GetPlaylist().GetID() == id {
playlistIsFinished = false
}
}
}
})
q.mutex.Lock()
})
q.mutex.Lock()
if playlistIsFinished {
DJ.Skips.ResetPlaylistSkips()
if playlistIsFinished {
DJ.Skips.ResetPlaylistSkips()
}
}
}