73 lines
1.1 KiB
Python
73 lines
1.1 KiB
Python
# Bryan Schumake (8/7/2010)
|
|
|
|
__all__ = ['audio']
|
|
|
|
import libsaria
|
|
call = libsaria.event.call
|
|
expand = libsaria.path.expand
|
|
exists = libsaria.path.exists
|
|
audio = None
|
|
tdelta = None
|
|
|
|
|
|
def init():
|
|
global tdelta
|
|
global audio
|
|
|
|
from datetime import timedelta as tdelta
|
|
import audio
|
|
audio.init()
|
|
|
|
|
|
def end_of_song():
|
|
global audio
|
|
return call("EOS", audio.reset)
|
|
|
|
|
|
def load(file):
|
|
global audio
|
|
if audio == None:
|
|
init()
|
|
|
|
global expand
|
|
file = expand(file)
|
|
if not exists(file):
|
|
return False
|
|
return call("LOAD", audio.load, file)
|
|
|
|
|
|
def play():
|
|
global audio
|
|
return call("PLAY", audio.play)
|
|
|
|
|
|
def pause():
|
|
global audio
|
|
print "pausing..."
|
|
return call("PAUSE", audio.pause)
|
|
libsaria.event.invite("PREEOS", pause)
|
|
|
|
|
|
def stop():
|
|
global audio
|
|
return call("STOP", audio.stop)
|
|
|
|
|
|
def get_progress():
|
|
global audio
|
|
dur = audio.duration()
|
|
if dur > 0:
|
|
return audio.position() / dur
|
|
return 0
|
|
|
|
|
|
def get_time():
|
|
global audio
|
|
global tdelta
|
|
pos = audio.position() / 1000
|
|
time = str(tdelta(microseconds=pos))
|
|
time = time.rsplit('.', 1)[0]
|
|
time = time.split(':', 1)[1]
|
|
return time
|
|
|