aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fischer@muhq.space>2022-08-01 22:12:13 +0200
committerFlorian Fischer <florian.fischer@muhq.space>2022-08-01 22:12:13 +0200
commit0f3042443c704df463f2c3bfb26190fc52ffa8aa (patch)
tree5c253987541fca30310def72dd48f4dbd5c17357
parentbb17b54478273116e1f48ff53476efb9f01cde7e (diff)
downloadWRMS-0f3042443c704df463f2c3bfb26190fc52ffa8aa.tar.gz
WRMS-0f3042443c704df463f2c3bfb26190fc52ffa8aa.zip
use llog in player.go
-rw-r--r--player.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/player.go b/player.go
index 91e3468..c7a9390 100644
--- a/player.go
+++ b/player.go
@@ -3,9 +3,10 @@ package main
import (
"fmt"
"io"
- "log"
"os/exec"
"syscall"
+
+ "muhq.space/wrms/llog"
)
type Backend interface {
@@ -25,7 +26,7 @@ func NewPlayer(wrms *Wrms) Player {
spotify, err := NewSpotify()
if err != nil {
// log.Fatalln("Error during initialization of the spotify backend:", err.Error())
- log.Println("Error during initialization of the spotify backend:", err.Error())
+ llog.Error(fmt.Sprintf("Error during initialization of the spotify backend: %s", err.Error()))
}
available_backends["spotify"] = spotify
available_backends["youtube"] = &YoutubeBackend{}
@@ -37,49 +38,50 @@ func NewPlayer(wrms *Wrms) Player {
func (player *Player) Play(song *Song) {
if player.mpv != nil {
- log.Println("Send SIGCONT to mpv subprocess")
+ llog.Debug("Send SIGCONT to mpv subprocess")
player.mpv.Process.Signal(syscall.SIGCONT)
return
}
- log.Println("Start playing", song)
+ llog.Info(fmt.Sprintf("Start playing %v", song))
player.Backends[song.Source].Play(song, player)
}
func (player *Player) runMpv() {
_, err := player.mpv.CombinedOutput()
if err != nil {
- log.Fatal(err)
+ llog.Fatal(err.Error())
}
- log.Println("mpv finished. Resetting mpv, the current song and call play")
+ llog.Info("mpv finished. Resetting mpv, the current song and call play")
player.mpv = nil
+ player.wrms.Playing = false
player.wrms.CurrentSong.Uri = ""
player.wrms.PlayPause()
}
func (player *Player) PlayUri(uri string) {
- log.Println("Start mpv with ", uri)
+ llog.Info(fmt.Sprintf("Start mpv with %s", uri))
player.mpv = exec.Command("mpv", "--no-video", uri)
go player.runMpv()
}
func (player *Player) PlayData(data io.Reader) {
if player.mpv != nil {
- log.Fatal("Player has already an mpv subprocess")
+ llog.Fatal("Player has already an mpv subprocess")
}
player.mpv = exec.Command("mpv", "-")
stdin, err := player.mpv.StdinPipe()
if err != nil {
- log.Fatal(err)
+ llog.Fatal(err.Error())
}
go func() {
defer stdin.Close()
if _, err := io.Copy(stdin, data); err != nil {
- log.Fatal(fmt.Sprintf("Failed to write song data to mpv (%v)", err))
+ llog.Fatal(fmt.Sprintf("Failed to write song data to mpv (%v)", err))
}
}()
@@ -88,7 +90,7 @@ func (player *Player) PlayData(data io.Reader) {
func (player *Player) Pause() {
if player.mpv != nil {
- log.Println("Send SIGSTOP to mpv subprocess")
+ llog.Debug("Send SIGSTOP to mpv subprocess")
player.mpv.Process.Signal(syscall.SIGSTOP)
}
}