ocarina/src/core/ct/gstreamer.py

108 lines
2.0 KiB
Python

#! /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
global pipeline
global time
global bin
pipeline = gst.Pipeline("player")
bin = gst.element_factory_make("playbin",None)
bin.set_state(gst.STATE_NULL)
time = gst.Format(gst.FORMAT_TIME)
# Volume range goes from 0 to 1.0 (before sounding bad)
volume = gst.element_factory_make("volume","vol")
#level = gst.element_factory_make("level","volume-level")
pipeline.add(bin,volume )#,level)
#level.set_property("peak-ttl",0)
#level.set_property("peak-falloff",20)
def load(path):
path = expandPath(path)
if checkPath(path) == False:
return
write("loading file: "+path, True)
global bin
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)
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 )
def init():
# Register signals
signal.register("play",play)
signal.register("pause",pause)
if settings.has("args") == True:
input = settings.get("args")
if not input == []:
join = ' '
path = join.join(input)
load(path)
if settings.has("volume") == False:
settings.set("volume",1.0)
setvol(settings.get("volume"))
def close():
global pipeline
global bin
pause()
pipeline.set_state(gst.STATE_NULL)
bin.set_state(gst.STATE_NULL)