Progress bar slider movement

The progress bar slider updates every half second as a song plays.
This commit is contained in:
Bryan Schumaker 2010-10-16 14:21:25 -04:00
parent 1da55341d4
commit 98ded4f032
3 changed files with 46 additions and 5 deletions

View File

@ -7,10 +7,14 @@ 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()
@ -47,3 +51,20 @@ def stop():
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

View File

@ -54,19 +54,23 @@ def duration():
return 0
if length == None:
length = player.query_duration(time)[0]
return length
return float(length)
def position():
global time
global player
return player.query_position(time)[0]
if get_state() == gst.STATE_NULL:
return float(0)
pos = player.query_position(time)[0]
return float(pos)
def load(file):
global gst
global player
player.set_state(gst.STATE_NULL)
reset()
#player.set_state(gst.STATE_NULL)
player.set_property("uri", "file://%s"%file)
player.set_state(gst.STATE_PAUSED)
return file

View File

@ -1,7 +1,17 @@
# Bryan Schumaker (10/11/2010)
import ocarina
gtk = ocarina.gtk
gtk = ocarina.gtk
gobject = ocarina.gobject
update = None
get_time = None
def set_fns():
global update
global get_time
update = ocarina.libsaria.music.get_progress
get_time = ocarina.libsaria.music.get_time
ocarina.libsaria.event.invite("POSTSTART", set_fns)
#class PBar(gtk.ProgressBar):
# def __init__(self):
@ -18,7 +28,13 @@ class PBar(gtk.HScale):
self.set_value_pos(gtk.POS_LEFT)
self.set_range(0, 101)
self.connect("format-value", self.format_value)
gobject.timeout_add(500, self.update)
self.show()
def format_value(self, scale, value):
return "00:00"
return get_time()
def update(self):
global update
self.set_value(update() * 100)
return True