#! /usr/bin/python # To change this template, choose Tools | Templates # and open the template in the editor. __author__="bjschuma" __date__ ="$May 11, 2010 11:50:23 PM$" import gst from gstreamer import player from gstreamer import time from gstreamer.playback import getstate def duration(): state = getstate() if (state!=gst.STATE_PLAYING) and (state!=gst.STATE_PAUSED): return 0 total = player.query_duration(time)[0] return total def currentpos(): state = getstate() if (state!=gst.STATE_PLAYING) and (state!=gst.STATE_PAUSED): return 0 position = player.query_position(time)[0] return position def getProgress(): state = getstate() if (state!=gst.STATE_PLAYING) and (state!=gst.STATE_PAUSED): return 0 total = duration() current = currentpos() fraction = float(current) / float(total) if fraction < 0.0: return 0.0 elif fraction > 1.0: return 1.0 return fraction # Seek to the desired percent of the song. # Fraction is True if prcnt is already a fraction def seek(prcnt): if prcnt < 0: prcnt = 0 elif prcnt > 100: prcnt = 1 elif prcnt > 1: prcnt = float(prcnt) / 100.0 newTime = duration() * prcnt player.seek_simple(time,gst.SEEK_FLAG_FLUSH,newTime) return 0