From 039881fdbfa69a33b27f84e8db3671fe8cfac5e6 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 31 May 2023 22:06:53 +0200 Subject: support skipping the current song while playback is paused --- player.go | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'player.go') diff --git a/player.go b/player.go index db4457c..2e1e7bf 100644 --- a/player.go +++ b/player.go @@ -48,15 +48,6 @@ func NewPlayer(wrms *Wrms, backends []string) Player { } func (player *Player) Play(song *Song) { - if player.mpv != nil { - llog.Debug("Send SIGCONT to mpv subprocess") - err := player.mpv.Process.Signal(syscall.SIGCONT) - if err != nil { - llog.Fatal("Failed to send SIGCONT to mpv") - } - return - } - llog.Info("Start playing %v", song) player.Backends[song.Source].Play(song, player) } @@ -65,7 +56,7 @@ func (player *Player) runMpv() { output, err := player.mpv.CombinedOutput() if err != nil { llog.Debug("Mpv output: %s", output) - llog.Fatal("Mpv failed with: %s", err.Error()) + llog.Fatal("Mpv failed with: %s", err) } currentSong := wrms.CurrentSong.Load() @@ -77,6 +68,15 @@ func (player *Player) runMpv() { wrms.Next() } +func (player *Player) terminateMpv() { + if player.mpv == nil { + llog.Fatal("Trying to terminate not running mpv process") + } + + player.mpv.Process.Signal(syscall.SIGTERM) + player.mpv = nil +} + const MPV_FLAGS = "--no-video" func mpvArgv(uri string) []string { @@ -133,6 +133,19 @@ func (player *Player) Pause() { } } +func (player *Player) Continue() { + if player.mpv == nil { + llog.Warning("Continue Play but there is no running mpv process to continue") + return + } + + llog.Debug("Send SIGCONT to mpv subprocess") + err := player.mpv.Process.Signal(syscall.SIGCONT) + if err != nil { + llog.Fatal("Failed to send SIGCONT to mpv") + } +} + func (player *Player) Search(pattern string) chan []Song { var wg sync.WaitGroup wg.Add(len(player.Backends)) -- cgit v1.2.3