# This is a simple test plugin, to make sure everything is working __author__="bjschuma" __date__ ="$Dec 21, 2009 11:58:37 PM$" from bt.file import * import gst import settings from manager import manager from cline import message global pipeline pipeline = None global time time = gst.Format(gst.FORMAT_TIME) def load(filename): filename = expandPath(filename) if checkPath(filename) == False: return write("loading file: "+filename,True) bin = gst.element_factory_make("playbin", None) bin.set_property("uri", "file://"+filename) bin.set_state(gst.STATE_PAUSED) global pipeline pipeline = gst.Pipeline("player") pipeline.add(bin) def play(): global pipeline pipeline.set_state(gst.STATE_PLAYING) def pause(): global pipeline pipeline.set_state(gst.STATE_PAUSED) def progress(): global pipeline global time # Don't bother to go on if the pipeline isn't playing if not pipeline.get_state()[1] == gst.STATE_PLAYING: return -1 position = pipeline.query_position(time)[0] total = pipeline.query_duration(time)[0] return float(position) / float(total) # If the song is done, play the next song def done(): p = progress() if p == -1: return max = int(settings.get("maxyx")[1] * p) bar = "=" message.disp(bar*max, settings.get("maxyx")[0]-1) if p == 1.0: #if position == total: manager.run("next") # Called every time the plugin is enabled def init(): global pipeline pipeline = gst.Pipeline() pipeline.set_state(gst.STATE_NULL) songs = settings.get("args") settings.set("everyloop",done) if len(songs) > 0: load(songs[0]) settings.replace("args", []) # Called every time the plugin is stopped def close(): global pipeline pipeline.set_state(gst.STATE_NULL) # Called when the plugin needs to perform some action def run(args=None): pass