diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2023-05-21 21:24:27 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2023-05-21 21:24:27 +0200 |
| commit | 70279c4c62ae4180706c0d27c5bbcf275c903100 (patch) | |
| tree | 486c471b61618a96d98d8603db188c2101dbb7bd /wrms.go | |
| parent | 95a65d718c3bc50324a0f4a75aa5a586eeadc4ef (diff) | |
| download | WRMS-70279c4c62ae4180706c0d27c5bbcf275c903100.tar.gz WRMS-70279c4c62ae4180706c0d27c5bbcf275c903100.zip | |
continue playback when adding a song to an empty queue
Now WRMS only switches the playback state when an admin calls the
/playpause endpoint.
When the queue runs out of songs the state is kept and continues
when a new song is added.
Diffstat (limited to 'wrms.go')
| -rw-r--r-- | wrms.go | 35 |
1 files changed, 21 insertions, 14 deletions
@@ -99,11 +99,22 @@ func (wrms *Wrms) Broadcast(ev Event) { } } +func (wrms *Wrms) startPlaying() { + wrms.Broadcast(Event{"play", []Song{wrms.CurrentSong}}) + wrms.Player.Play(&wrms.CurrentSong) +} + func (wrms *Wrms) AddSong(song Song) { + startPlayingAgain := wrms.Playing && wrms.CurrentSong.Uri == "" wrms.Songs = append(wrms.Songs, song) s := &wrms.Songs[len(wrms.Songs)-1] wrms.queue.Add(s) llog.Info("Added song %s (ptr=%p) to Songs", s.Uri, s) + wrms.Broadcast(Event{"add", []Song{song}}) + + if startPlayingAgain { + wrms.Next() + } } func (wrms *Wrms) Next() { @@ -112,6 +123,7 @@ func (wrms *Wrms) Next() { next := wrms.queue.PopSong() if next == nil { wrms.CurrentSong.Uri = "" + wrms.Broadcast(newNotification("stop")) return } @@ -126,30 +138,25 @@ func (wrms *Wrms) Next() { } wrms.CurrentSong = *next + if wrms.Playing { + wrms.startPlaying() + } } func (wrms *Wrms) PlayPause() { - var ev Event - if !wrms.Playing { + wrms.Playing = !wrms.Playing + + if wrms.Playing { if wrms.CurrentSong.Uri == "" { llog.Info("No song currently playing play the next") wrms.Next() - if wrms.CurrentSong.Uri == "" { - llog.Info("No song left to play") - wrms.Broadcast(newNotification("stop")) - return - } + } else { + wrms.startPlaying() } - ev = Event{"play", []Song{wrms.CurrentSong}} - wrms.Player.Play(&wrms.CurrentSong) } else { - ev = newNotification("pause") + wrms.Broadcast(newNotification("pause")) wrms.Player.Pause() } - - wrms.Playing = !wrms.Playing - - wrms.Broadcast(ev) } func (wrms *Wrms) AdjustSongWeight(connId uuid.UUID, songUri string, vote string) { |
