2010-02-05 23:36:54 -05:00
|
|
|
#! /usr/bin/python
|
|
|
|
|
|
|
|
# To change this template, choose Tools | Templates
|
|
|
|
# and open the template in the editor.
|
|
|
|
|
|
|
|
__author__="bjschuma"
|
|
|
|
__date__ ="$Feb 5, 2010 7:53:19 PM$"
|
|
|
|
|
|
|
|
|
|
|
|
import gst
|
|
|
|
import settings
|
|
|
|
|
|
|
|
from bt.file import *
|
|
|
|
from bt import signal
|
|
|
|
from bt.message import write
|
2010-02-12 20:13:39 -05:00
|
|
|
import manager
|
|
|
|
import cline
|
2010-02-05 23:36:54 -05:00
|
|
|
|
|
|
|
global pipeline
|
|
|
|
global time
|
2010-02-08 19:03:12 -05:00
|
|
|
global bin
|
2010-02-12 20:13:39 -05:00
|
|
|
global bus
|
2010-02-08 19:03:12 -05:00
|
|
|
|
|
|
|
pipeline = gst.Pipeline("player")
|
|
|
|
|
|
|
|
bin = gst.element_factory_make("playbin",None)
|
|
|
|
bin.set_state(gst.STATE_NULL)
|
2010-02-05 23:36:54 -05:00
|
|
|
time = gst.Format(gst.FORMAT_TIME)
|
|
|
|
|
2010-02-08 19:03:12 -05:00
|
|
|
# Volume range goes from 0 to 1.0 (before sounding bad)
|
|
|
|
volume = gst.element_factory_make("volume","vol")
|
2010-02-12 20:13:39 -05:00
|
|
|
pipeline.add(bin,volume)
|
|
|
|
bus = pipeline.get_bus()
|
2010-02-08 19:03:12 -05:00
|
|
|
|
2010-02-05 23:36:54 -05:00
|
|
|
|
|
|
|
def load(path):
|
|
|
|
path = expandPath(path)
|
|
|
|
if checkPath(path) == False:
|
|
|
|
return
|
|
|
|
|
|
|
|
write("loading file: "+path, True)
|
2010-02-08 19:03:12 -05:00
|
|
|
global bin
|
2010-02-05 23:36:54 -05:00
|
|
|
bin.set_property("uri", "file://"+path)
|
|
|
|
bin.set_state(gst.STATE_PAUSED)
|
|
|
|
|
|
|
|
|
|
|
|
def play():
|
|
|
|
global pipeline
|
|
|
|
if not pipeline == None:
|
|
|
|
pipeline.set_state(gst.STATE_PLAYING)
|
|
|
|
|
|
|
|
|
|
|
|
def pause():
|
|
|
|
global pipeline
|
|
|
|
if not pipeline == None:
|
|
|
|
pipeline.set_state(gst.STATE_PAUSED)
|
|
|
|
|
|
|
|
|
2010-02-08 19:03:12 -05:00
|
|
|
def setvol(value):
|
|
|
|
global pipeline
|
|
|
|
curvol = float( settings.get("volume") )
|
|
|
|
|
|
|
|
vol = pipeline.get_by_name("vol")
|
|
|
|
if value == "up":
|
|
|
|
value = curvol + 0.05
|
|
|
|
elif value == "down":
|
|
|
|
value = curvol - 0.05
|
|
|
|
else:
|
|
|
|
# Prevent converting strings
|
|
|
|
try:
|
|
|
|
value = float(value)
|
|
|
|
except:
|
|
|
|
return
|
|
|
|
|
|
|
|
if value > 1.0:
|
|
|
|
value = 1.0
|
|
|
|
if value < 0.0:
|
|
|
|
value = 0.0
|
|
|
|
settings.set("volume",value)
|
|
|
|
vol.set_property("volume",value )
|
|
|
|
|
|
|
|
|
2010-02-12 20:13:39 -05:00
|
|
|
def getProgress(tuple=False):
|
|
|
|
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]
|
|
|
|
if tuple==False:
|
|
|
|
return float(position) / float(total)
|
|
|
|
else:
|
|
|
|
return (position,total)
|
|
|
|
|
|
|
|
|
|
|
|
# Draw the progress bar on the command line
|
|
|
|
def drawProgress():
|
|
|
|
p = getProgress()
|
|
|
|
if p == -1:
|
|
|
|
return
|
|
|
|
win = settings.get("maxyx")
|
|
|
|
max = int(win[1] * p)
|
|
|
|
if max == 0:
|
|
|
|
cline.message.disp(" "*(win[1]-1) ,win[0]-1)
|
|
|
|
else:
|
|
|
|
cline.message.disp("="*max, win[0]-1)
|
|
|
|
|
|
|
|
|
|
|
|
# A callback when there are messages on the bus
|
|
|
|
def onMessage(bus,message):
|
|
|
|
if message.type == gst.MESSAGE_EOS:
|
|
|
|
manager.run("next")
|
|
|
|
|
|
|
|
|
|
|
|
# Manually check the bus for messages
|
|
|
|
def checkBus():
|
|
|
|
global bus
|
|
|
|
if bus.peek() == None:
|
|
|
|
return
|
|
|
|
onMessage(bus,bus.pop())
|
|
|
|
|
2010-02-08 19:03:12 -05:00
|
|
|
|
|
|
|
|
2010-02-05 23:36:54 -05:00
|
|
|
def init():
|
|
|
|
# Register signals
|
|
|
|
signal.register("play",play)
|
|
|
|
signal.register("pause",pause)
|
2010-02-12 20:13:39 -05:00
|
|
|
signal.register("cliloop",drawProgress)
|
|
|
|
signal.register("cliloop",checkBus,90)
|
2010-02-05 23:36:54 -05:00
|
|
|
|
2010-02-12 20:13:39 -05:00
|
|
|
# Check for settings values
|
2010-02-05 23:36:54 -05:00
|
|
|
if settings.has("args") == True:
|
|
|
|
input = settings.get("args")
|
|
|
|
if not input == []:
|
|
|
|
join = ' '
|
|
|
|
path = join.join(input)
|
|
|
|
load(path)
|
2010-02-08 19:03:12 -05:00
|
|
|
if settings.has("volume") == False:
|
|
|
|
settings.set("volume",1.0)
|
|
|
|
setvol(settings.get("volume"))
|
2010-02-05 23:36:54 -05:00
|
|
|
|
|
|
|
|
|
|
|
def close():
|
|
|
|
global pipeline
|
2010-02-08 19:03:12 -05:00
|
|
|
global bin
|
|
|
|
pause()
|
|
|
|
pipeline.set_state(gst.STATE_NULL)
|
|
|
|
bin.set_state(gst.STATE_NULL)
|