Can change the volume of the gstreamer pipeline
This commit is contained in:
parent
75ae830ef2
commit
8a1f5c820f
|
@ -16,9 +16,23 @@ from bt.message import write
|
||||||
|
|
||||||
global pipeline
|
global pipeline
|
||||||
global time
|
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)
|
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):
|
def load(path):
|
||||||
path = expandPath(path)
|
path = expandPath(path)
|
||||||
|
@ -26,14 +40,10 @@ def load(path):
|
||||||
return
|
return
|
||||||
|
|
||||||
write("loading file: "+path, True)
|
write("loading file: "+path, True)
|
||||||
bin = gst.element_factory_make("playbin",None)
|
global bin
|
||||||
bin.set_property("uri", "file://"+path)
|
bin.set_property("uri", "file://"+path)
|
||||||
bin.set_state(gst.STATE_PAUSED)
|
bin.set_state(gst.STATE_PAUSED)
|
||||||
|
|
||||||
global pipeline
|
|
||||||
pipeline = gst.Pipeline("player")
|
|
||||||
pipeline.add(bin)
|
|
||||||
|
|
||||||
|
|
||||||
def play():
|
def play():
|
||||||
global pipeline
|
global pipeline
|
||||||
|
@ -47,6 +57,32 @@ def pause():
|
||||||
pipeline.set_state(gst.STATE_PAUSED)
|
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():
|
def init():
|
||||||
# Register signals
|
# Register signals
|
||||||
signal.register("play",play)
|
signal.register("play",play)
|
||||||
|
@ -58,11 +94,14 @@ def init():
|
||||||
join = ' '
|
join = ' '
|
||||||
path = join.join(input)
|
path = join.join(input)
|
||||||
load(path)
|
load(path)
|
||||||
|
if settings.has("volume") == False:
|
||||||
|
settings.set("volume",1.0)
|
||||||
|
setvol(settings.get("volume"))
|
||||||
|
|
||||||
|
|
||||||
def close():
|
def close():
|
||||||
global pipeline
|
global pipeline
|
||||||
if not pipeline == None:
|
global bin
|
||||||
pause()
|
pause()
|
||||||
pipeline.set_state(gst.STATE_NULL)
|
pipeline.set_state(gst.STATE_NULL)
|
||||||
pipeline = None
|
bin.set_state(gst.STATE_NULL)
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Plugin(plugin.Plugin):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
plugin.Plugin.__init__(self)
|
plugin.Plugin.__init__(self)
|
||||||
self.help = "Used to control various aspects of playback"
|
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):
|
def loadTrack(self,args):
|
||||||
|
@ -43,4 +43,7 @@ class Plugin(plugin.Plugin):
|
||||||
elif args[0] == "pause":
|
elif args[0] == "pause":
|
||||||
signal.emit("pause")
|
signal.emit("pause")
|
||||||
|
|
||||||
|
elif args[0] == "vol":
|
||||||
|
gstreamer.setvol(args[1])
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue