diff --git a/cmd/daemon/controls.go b/cmd/daemon/controls.go index b160aae..2ea28ea 100644 --- a/cmd/daemon/controls.go +++ b/cmd/daemon/controls.go @@ -236,6 +236,20 @@ func (p *AppPlayer) setShufflingContext(val bool) { }) } +func (p *AppPlayer) addToQueue(track *connectpb.ContextTrack) { + p.state.tracks.AddToQueue(track) + p.state.player.PrevTracks = p.state.tracks.PrevTracks() + p.state.player.NextTracks = p.state.tracks.NextTracks() + p.updateState() +} + +func (p *AppPlayer) setQueue(prev []*connectpb.ContextTrack, next []*connectpb.ContextTrack) { + p.state.tracks.SetQueue(prev, next) + p.state.player.PrevTracks = p.state.tracks.PrevTracks() + p.state.player.NextTracks = p.state.tracks.NextTracks() + p.updateState() +} + func (p *AppPlayer) play() error { if p.stream == nil { return fmt.Errorf("no stream") diff --git a/cmd/daemon/player.go b/cmd/daemon/player.go index a2f996e..d8ca4f2 100644 --- a/cmd/daemon/player.go +++ b/cmd/daemon/player.go @@ -259,16 +259,10 @@ func (p *AppPlayer) handlePlayerCommand(req dealer.RequestPayload) error { p.setShufflingContext(req.Command.Value.(bool)) return nil case "set_queue": - p.state.tracks.SetQueue(req.Command.PrevTracks, req.Command.NextTracks) - p.state.player.PrevTracks = p.state.tracks.PrevTracks() - p.state.player.NextTracks = p.state.tracks.NextTracks() - p.updateState() + p.setQueue(req.Command.PrevTracks, req.Command.NextTracks) return nil case "add_to_queue": - p.state.tracks.AddToQueue(req.Command.Track) - p.state.player.PrevTracks = p.state.tracks.PrevTracks() - p.state.player.NextTracks = p.state.tracks.NextTracks() - p.updateState() + p.addToQueue(req.Command.Track) return nil default: return fmt.Errorf("unsupported player command: %s", req.Command.Endpoint)