From 1f08ccf2f4cf390067b2eb9605fdfc267c10b31e Mon Sep 17 00:00:00 2001 From: Alex McGrath Date: Sun, 19 Apr 2020 19:15:00 +0100 Subject: [PATCH] Improve compatibility with the subsonic api This seems to be how its supposed to be implemented set - should only change current playlist and shouldnt modify index This lets dsub work properly when it comes to modifying the current playlist as it does a combination of "set" and "skip" Itll only use set if its adding tracks to the playlist and includes the whole playlist, and itll use both set and skip to set the current playing and skip back to the first track --- server/jukebox/jukebox.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/server/jukebox/jukebox.go b/server/jukebox/jukebox.go index 6450e7a..83c18ea 100644 --- a/server/jukebox/jukebox.go +++ b/server/jukebox/jukebox.go @@ -96,20 +96,8 @@ func (j *Jukebox) doUpdate(u update) { j.Lock() switch u.action { case set: - if j.playing { - speaker.Clear() - } - speaker.Clear() - if len(u.tracks) == 0 { - j.playlist = []*db.Track{} - j.Unlock() - return - } j.playlist = u.tracks - j.index = 0 - j.playing = true j.Unlock() - j.speaker <- updateSpeaker{j.index} case clear: speaker.Clear() j.playing = false @@ -118,12 +106,23 @@ func (j *Jukebox) doUpdate(u update) { case skip: speaker.Clear() j.index = u.index + j.playing = true j.Unlock() j.speaker <- updateSpeaker{j.index} case add: + if len(j.playlist) == 0 { + j.playlist = u.tracks + j.playing = true + j.index = 0 + j.Unlock() + j.speaker <- updateSpeaker{0} + return + } j.playlist = append(j.playlist, u.tracks...) + j.Unlock() case remove: - if u.index < 0 || u.index > len(j.playlist) { + if u.index < 0 || u.index >= len(j.playlist) { + j.Unlock() return } j.playlist = append(j.playlist[:u.index], j.playlist[u.index+1:]...) @@ -144,10 +143,15 @@ func (j *Jukebox) doUpdate(u update) { } func (j *Jukebox) doUpdateSpeaker(su updateSpeaker) error { - if su.index > len(j.playlist)-1 { + if su.index >= len(j.playlist) { + j.Lock() j.playing = false + j.Unlock() return nil } + j.Lock() + j.index = su.index + j.Unlock() f, err := os.Open(path.Join( j.musicPath, j.playlist[su.index].RelPath(),