ocarina/src/core/ct/gstreamer.py

68 lines
1.2 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
pipeline = None
time = gst.Format(gst.FORMAT_TIME)
def load(path):
path = expandPath(path)
if checkPath(path) == False:
return
write("loading file: "+path, True)
bin = gst.element_factory_make("playbin",None)
bin.set_property("uri", "file://"+path)
bin.set_state(gst.STATE_PAUSED)
global pipeline
pipeline = gst.Pipeline("player")
pipeline.add(bin)
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 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)
def close():
global pipeline
if not pipeline == None:
pause()
pipeline.set_state(gst.STATE_NULL)
pipeline = None