ocarina/libsaria/music/__init__.py

84 lines
1.3 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 ls_init():
libsaria.init_pref("volume", 1.0)
libsaria.event.invite("POSTINIT", ls_init)
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
return call("PAUSE", audio.pause)
libsaria.event.invite("PREEOS", pause)
def stop():
global audio
return call("STOP", audio.stop)
def seek(prcnt):
global audio
return call("SEEK", audio.seek, prcnt)
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
def set_volume(prcnt):
global audio
return call("SETVOLUME", audio.set_volume, prcnt)