aboutsummaryrefslogtreecommitdiff
path: root/wrms.go
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2023-06-30 18:08:07 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2023-06-30 18:09:47 +0200
commit6c81e0dcaf5905c6fac3fe4b62dffaf67027d785 (patch)
tree49ac3fb95a6832b8fb770137b583a7f5d00756ab /wrms.go
parent8b29c4431d42f308f2f52d4c35129dae5d86a136 (diff)
downloadWRMS-6c81e0dcaf5905c6fac3fe4b62dffaf67027d785.tar.gz
WRMS-6c81e0dcaf5905c6fac3fe4b62dffaf67027d785.zip
fix double _next call and move mpv termination to Next
Due to an logic error was _next() a second time from runMpv after the mpv subprocess was terminated by the first Next() call.
Diffstat (limited to 'wrms.go')
-rw-r--r--wrms.go24
1 files changed, 15 insertions, 9 deletions
diff --git a/wrms.go b/wrms.go
index 5b7fcf3..1f74957 100644
--- a/wrms.go
+++ b/wrms.go
@@ -266,7 +266,7 @@ func (wrms *Wrms) AddSong(song Song) {
wrms.Broadcast(newEvent("add", []Song{song}))
if startPlayingAgain {
- wrms.Next()
+ wrms._lockedNext()
}
}
@@ -293,24 +293,28 @@ func (wrms *Wrms) DeleteSong(songUri string) {
func (wrms *Wrms) Next() {
wrms.rwlock.Lock()
- wrms._next()
-}
-
-func (wrms *Wrms) _next() {
- llog.DDebug("Next Song")
-
- cmd := "play"
// Terminate the mpv process playing the current song
if wrms.Player.mpv.Load() != nil {
wrms.Player.Stop()
- cmd = "next"
}
+ wrms._next()
+}
+
+func (wrms *Wrms) _lockedNext() {
+ wrms.rwlock.Lock()
+ wrms._next()
+}
+
+func (wrms *Wrms) _next() {
+ llog.DDebug("Next Song")
+
next := wrms.queue.PopSong()
if next == nil {
wrms.CurrentSong.Store(nil)
wrms.Broadcast(newNotification("stop"))
+ wrms.rwlock.Unlock()
return
}
@@ -326,9 +330,11 @@ func (wrms *Wrms) _next() {
}
}
+ cmd := "next"
// We are playing -> start playing the next song
if wrms.Playing {
wrms.Player.Play(next)
+ cmd = "play"
}
wrms.rwlock.Unlock()