From ae47f8163880177cdee15a369a334446101fc38d Mon Sep 17 00:00:00 2001 From: Brendan Howell Date: Tue, 30 Apr 2019 16:58:31 +0200 Subject: [PATCH] rewrite audio playback to use vlc instead of moc --- screenless/bureau/audio/audio.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/screenless/bureau/audio/audio.py b/screenless/bureau/audio/audio.py index 6d6574d..6945616 100644 --- a/screenless/bureau/audio/audio.py +++ b/screenless/bureau/audio/audio.py @@ -1,4 +1,4 @@ -import subprocess +import vlc from bureau import Bureau, add_command @@ -17,7 +17,7 @@ class Audio(Bureau): Bureau.__init__(self) self.urldb = self.open_db("urldb") - subprocess.call(["mocp", "-S"]) + self.player = vlc.MediaPlayer() @add_command("p", "Play an album, track or a live stream.") def play(self, data): @@ -31,44 +31,52 @@ class Audio(Bureau): url = self.urldb.get(shortcode) self.log.debug(" playing url " + url) - subprocess.call(["mocp", "-c"]) - subprocess.call(["mocp", "-a", url]) - subprocess.call(["mocp", "-p"]) + self.player.set_mrl(url) + self.player.play() @add_command("stop", "Halt audio playback.") def stop(self): """ Stops all audio currently playing audio output. """ - subprocess.call(["mocp", "-P"]) + self.player.pause() @add_command("resu", "Resume playback.") def resume(self): """ Resume playback of paused audio. """ - subprocess.call(["mocp", "-U"]) + self.player.play() @add_command("next", "Play the next song.") def play_next(self): """ Skip to the next song in the playlist or album. """ - subprocess.call(["mocp", "-f"]) + #subprocess.call(["mocp", "-f"]) + # TODO + pass @add_command("prev", "Play the previous song.") def play_prev(self): """ Skip to the previous song in the playlist or album. """ - subprocess.call(["mocp", "-r"]) + #subprocess.call(["mocp", "-r"]) + # TODO + pass @add_command("nowp", "Now Playing") def now_playing(self): """ Prints the currently playing song or stream on the small printer. """ - out = subprocess.check_output(["mocp", "-i"]).decode("utf-8") + #out = subprocess.check_output(["mocp", "-i"]).decode("utf-8") + # TODO: sort out how to do this with + out = "Now Playing: " + out += self.player.get_media().get_meta(0) + "\n" + out += "by " + self.player.get_media().get_meta(1) + "\n" + self.log.debug("info output:" + out) self.print_small(out)