ocarina/libsaria/controls.py
Bryan Schumaker 3abc80bdc4 Add seeking to controls
Seeking should be part of controls, rather than existing independently
as part of the audio package.  This patch moves the seeking functions,
and removes the need to pass a specific number of seconds.
2010-12-16 22:08:26 -05:00

95 lines
1.7 KiB
Python

# Bryan Schumaker (11/23/2010)
libsaria = None
sources = None
library = None
playlist = None
queue = None
audio = None
call = None
invite = None
prefs = None
expand = None
exists = None
def init():
global libsaria
import libsaria
libsaria.init_pref("libsaria.random", False)
def init2():
global call
global audio
global invite
global prefs
global sources
global library
global playlist
global expand
global exists
global queue
call = libsaria.event.call
invite = libsaria.event.invite
prefs = libsaria.prefs
expand = libsaria.path.expand
exists = libsaria.path.exists
sources = libsaria.sources
library = sources.library
playlist = sources.playlist
queue = sources.queue
from libsaria.audio import audio
invite("PREEOS", pause)
invite("POSTEOS", catch_eos)
def pick_next():
file = queue.next()
if file == None:
file = playlist.next()
load(file)
play()
def catch_eos(*args):
library.inc_count()
library.inc_score()
return call("NEXT", pick_next)
def next():
library.change_score()
return call("NEXT", pick_next)
def play():
return call("PLAY", audio.play)
def pause():
return call("PAUSE", audio.pause)
def toggle_play():
if audio.get_state() == audio.gst.STATE_PAUSED:
play()
else:
pause()
def stop():
return call("STOP", audio.stop)
def seek_forward():
libsaria.audio.seek_sec(5)
def seek_backward():
libsaria.audio.seek_sec(-5)
def set_volume(prcnt):
return call("SETVOLUME", audio.set_volume, prcnt)
def toggle_rand():
prefs.set_pref("libsaria.random", not prefs.get_pref("libsaria.random"))
def load(file):
file = expand(file)
if not exists(file):
return False
return call("LOAD", audio.load, file)