audio start/stop/pause/next/prev all using MOC

workspace
Brendan Howell 7 years ago
parent c0433e715a
commit 7b46a865fb

@ -1,4 +1,4 @@
import mplayer
import subprocess
from bureau import Bureau, add_command
@ -16,8 +16,8 @@ class Audio(Bureau):
def __init__(self):
Bureau.__init__(self)
self.player = mplayer.Player()
self.urldb = self.open_db("urldb")
subprocess.call(["mocp", "-S"])
@add_command("p", "Play an album, track or a live stream.")
def play(self, data):
@ -29,10 +29,45 @@ class Audio(Bureau):
shortcode, _ = data.split(".")
url = self.urldb.get(shortcode)
if not self.player.is_alive():
self.player.spawn()
subprocess.call(["mocp", "-c"])
subprocess.call(["mocp", "-a", url])
subprocess.call(["mocp", "-p"])
self.player.loadfile(url)
@add_command("stop", "Halt audio playback.")
def stop(self):
"""
Stops all audio currently playing audio output.
"""
subprocess.call(["mocp", "-P"])
@add_command("resu", "Resume playback.")
def resume(self):
"""
Resume playback of paused audio.
"""
subprocess.call(["mocp", "-U"])
@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"])
@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"])
@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"])
self.print_small(out)
def save_url(self, url):
"""

Loading…
Cancel
Save