You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
Python
52 lines
1.2 KiB
Python
![]()
6 years ago
|
import mplayer
|
||
|
|
||
|
from bureau import Bureau, add_command
|
||
|
|
||
|
|
||
|
class Audio(Bureau):
|
||
|
"""
|
||
|
The Audio Services department provides for playback and recording
|
||
|
of sound within the office environment.
|
||
|
"""
|
||
|
|
||
|
name = "Audio Services Dept."
|
||
|
prefix = "AU"
|
||
|
version = 0
|
||
|
|
||
|
def __init__(self):
|
||
|
Bureau.__init__(self)
|
||
|
|
||
|
self.player = mplayer.Player()
|
||
|
self.urldb = self.open_db("urldb")
|
||
|
|
||
|
@add_command("p", "Play an album, track or a live stream.")
|
||
|
def play(self, data):
|
||
|
"""
|
||
|
Initiates playback of a media reference. This could be a song or album
|
||
|
stored on the local office or remote URLs for live playback. Currently,
|
||
|
only supports line-out signals on the default DAC.
|
||
|
"""
|
||
|
shortcode, _ = data.split(".")
|
||
|
url = self.urldb.get(shortcode)
|
||
|
|
||
|
if not self.player.is_alive():
|
||
|
self.player.spawn()
|
||
|
|
||
|
self.player.loadfile(url)
|
||
|
|
||
|
def save_url(self, url):
|
||
|
"""
|
||
|
saves an url for a local file or network audio stream.
|
||
|
"""
|
||
|
code = self.urldb.store_and_get_shortcode(url)
|
||
|
print("saved url with shortcode: ", code)
|
||
|
|
||
|
|
||
|
def main():
|
||
|
au = Audio()
|
||
|
au.run()
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|