Can change the volume of the gstreamer pipeline

This commit is contained in:
bjschuma 2010-02-08 19:03:12 -05:00
parent 75ae830ef2
commit 8a1f5c820f
2 changed files with 53 additions and 11 deletions

View File

@ -16,9 +16,23 @@ from bt.message import write
global pipeline
global time
pipeline = None
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)
@ -26,14 +40,10 @@ def load(path):
return
write("loading file: "+path, True)
bin = gst.element_factory_make("playbin",None)
global bin
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
@ -47,6 +57,32 @@ def pause():
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)
@ -58,11 +94,14 @@ def init():
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
if not pipeline == None:
pause()
pipeline.set_state(gst.STATE_NULL)
pipeline = None
global bin
pause()
pipeline.set_state(gst.STATE_NULL)
bin.set_state(gst.STATE_NULL)

View File

@ -15,7 +15,7 @@ class Plugin(plugin.Plugin):
def __init__(self):
plugin.Plugin.__init__(self)
self.help = "Used to control various aspects of playback"
self.usage = "music [load, pause, play]"
self.usage = "music [load, pause, play, vol]"
def loadTrack(self,args):
@ -43,4 +43,7 @@ class Plugin(plugin.Plugin):
elif args[0] == "pause":
signal.emit("pause")
elif args[0] == "vol":
gstreamer.setvol(args[1])