From 8a1f5c820f77e98186caa1692f64f8130bf3a454 Mon Sep 17 00:00:00 2001 From: bjschuma Date: Mon, 8 Feb 2010 19:03:12 -0500 Subject: [PATCH] Can change the volume of the gstreamer pipeline --- src/core/ct/gstreamer.py | 59 +++++++++++++++++++++++++++++++++------- src/core/music.py | 5 +++- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/core/ct/gstreamer.py b/src/core/ct/gstreamer.py index 47adce41..3acc7707 100644 --- a/src/core/ct/gstreamer.py +++ b/src/core/ct/gstreamer.py @@ -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 \ No newline at end of file + global bin + pause() + pipeline.set_state(gst.STATE_NULL) + bin.set_state(gst.STATE_NULL) diff --git a/src/core/music.py b/src/core/music.py index 41631686..65e9454e 100644 --- a/src/core/music.py +++ b/src/core/music.py @@ -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]) +