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 | |
| 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.
| -rw-r--r-- | TODO.md | 2 | ||||
| -rw-r--r-- | main.go | 1 | ||||
| -rw-r--r-- | player.go | 6 | ||||
| -rw-r--r-- | upload.go | 1 | ||||
| -rw-r--r-- | web/client.html | 1 | ||||
| -rw-r--r-- | wrms.go | 35 |
6 files changed, 24 insertions, 22 deletions
@@ -2,7 +2,7 @@ - [X] add admin - [ ] allow admin to delete songs -- [ ] continue playback when song is added to empty playlist +- [X] continue playback when song is added to empty playlist ## Fronted @@ -137,7 +137,6 @@ func addHandler(w http.ResponseWriter, r *http.Request) { } wrms.AddSong(song) - wrms.Broadcast(Event{"add", []Song{song}}) fmt.Fprintf(w, "Added song %s", string(data)) } @@ -68,13 +68,11 @@ func (player *Player) runMpv() { wrms := player.wrms - llog.Info("mpv finished. Resetting mpv, the current song and call play") + llog.Info("mpv finished. Resetting mpv, and calling next") player.mpv = nil - wrms.Playing = false player.Backends[wrms.CurrentSong.Source].OnSongFinished(&wrms.CurrentSong) - wrms.CurrentSong.Uri = "" - wrms.PlayPause() + wrms.Next() } func (player *Player) PlayUri(uri string) { @@ -66,7 +66,6 @@ func (b *UploadBackend) upload(w http.ResponseWriter, r *http.Request) { } wrms.AddSong(song) - wrms.Broadcast(Event{"add", []Song{song}}) fmt.Fprintf(w, "Added uploaded song %s", string(fileName)) } diff --git a/web/client.html b/web/client.html index 77a4bfe..a4818af 100644 --- a/web/client.html +++ b/web/client.html @@ -170,7 +170,6 @@ } function handleStop() { - {{if .IsAdmin}} document.getElementById("ppbutton").innerHTML = 'Play'; {{end}} playing = document.getElementById("playing").innerHTML = ""; } @@ -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) { |
