Manually check the gstreamer bus for new messages
This commit is contained in:
parent
05f09dfdfb
commit
808bc88dfa
|
@ -13,10 +13,13 @@ import settings
|
||||||
from bt.file import *
|
from bt.file import *
|
||||||
from bt import signal
|
from bt import signal
|
||||||
from bt.message import write
|
from bt.message import write
|
||||||
|
import manager
|
||||||
|
import cline
|
||||||
|
|
||||||
global pipeline
|
global pipeline
|
||||||
global time
|
global time
|
||||||
global bin
|
global bin
|
||||||
|
global bus
|
||||||
|
|
||||||
pipeline = gst.Pipeline("player")
|
pipeline = gst.Pipeline("player")
|
||||||
|
|
||||||
|
@ -26,12 +29,8 @@ time = gst.Format(gst.FORMAT_TIME)
|
||||||
|
|
||||||
# Volume range goes from 0 to 1.0 (before sounding bad)
|
# Volume range goes from 0 to 1.0 (before sounding bad)
|
||||||
volume = gst.element_factory_make("volume","vol")
|
volume = gst.element_factory_make("volume","vol")
|
||||||
|
pipeline.add(bin,volume)
|
||||||
#level = gst.element_factory_make("level","volume-level")
|
bus = pipeline.get_bus()
|
||||||
|
|
||||||
pipeline.add(bin,volume )#,level)
|
|
||||||
#level.set_property("peak-ttl",0)
|
|
||||||
#level.set_property("peak-falloff",20)
|
|
||||||
|
|
||||||
|
|
||||||
def load(path):
|
def load(path):
|
||||||
|
@ -81,13 +80,58 @@ def setvol(value):
|
||||||
vol.set_property("volume",value )
|
vol.set_property("volume",value )
|
||||||
|
|
||||||
|
|
||||||
|
def getProgress(tuple=False):
|
||||||
|
global pipeline
|
||||||
|
global time
|
||||||
|
|
||||||
|
# Don't bother to go on if the pipeline isn't playing
|
||||||
|
if not pipeline.get_state()[1] == gst.STATE_PLAYING:
|
||||||
|
return -1
|
||||||
|
|
||||||
|
position = pipeline.query_position(time)[0]
|
||||||
|
total = pipeline.query_duration(time)[0]
|
||||||
|
if tuple==False:
|
||||||
|
return float(position) / float(total)
|
||||||
|
else:
|
||||||
|
return (position,total)
|
||||||
|
|
||||||
|
|
||||||
|
# Draw the progress bar on the command line
|
||||||
|
def drawProgress():
|
||||||
|
p = getProgress()
|
||||||
|
if p == -1:
|
||||||
|
return
|
||||||
|
win = settings.get("maxyx")
|
||||||
|
max = int(win[1] * p)
|
||||||
|
if max == 0:
|
||||||
|
cline.message.disp(" "*(win[1]-1) ,win[0]-1)
|
||||||
|
else:
|
||||||
|
cline.message.disp("="*max, win[0]-1)
|
||||||
|
|
||||||
|
|
||||||
|
# A callback when there are messages on the bus
|
||||||
|
def onMessage(bus,message):
|
||||||
|
if message.type == gst.MESSAGE_EOS:
|
||||||
|
manager.run("next")
|
||||||
|
|
||||||
|
|
||||||
|
# Manually check the bus for messages
|
||||||
|
def checkBus():
|
||||||
|
global bus
|
||||||
|
if bus.peek() == None:
|
||||||
|
return
|
||||||
|
onMessage(bus,bus.pop())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
# Register signals
|
# Register signals
|
||||||
signal.register("play",play)
|
signal.register("play",play)
|
||||||
signal.register("pause",pause)
|
signal.register("pause",pause)
|
||||||
|
signal.register("cliloop",drawProgress)
|
||||||
|
signal.register("cliloop",checkBus,90)
|
||||||
|
|
||||||
|
# Check for settings values
|
||||||
if settings.has("args") == True:
|
if settings.has("args") == True:
|
||||||
input = settings.get("args")
|
input = settings.get("args")
|
||||||
if not input == []:
|
if not input == []:
|
||||||
|
|
|
@ -6,16 +6,18 @@ __date__ ="$Feb 5, 2010 7:47:18 PM$"
|
||||||
|
|
||||||
from bt import plugin
|
from bt import plugin
|
||||||
from bt.message import write
|
from bt.message import write
|
||||||
|
from bt import sql
|
||||||
from bt import signal
|
from bt import signal
|
||||||
|
|
||||||
from ct import gstreamer
|
from ct import gstreamer
|
||||||
|
import settings
|
||||||
|
|
||||||
|
|
||||||
class Plugin(plugin.Plugin):
|
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, vol]"
|
self.usage = "music [load, whatis, now, pause, play, vol]"
|
||||||
|
|
||||||
|
|
||||||
def loadTrack(self,args):
|
def loadTrack(self,args):
|
||||||
|
@ -23,11 +25,33 @@ class Plugin(plugin.Plugin):
|
||||||
write("Usage: music load track")
|
write("Usage: music load track")
|
||||||
join = ' '
|
join = ' '
|
||||||
path = join.join(args)
|
path = join.join(args)
|
||||||
write("Loading: "+path)
|
write("Loading: "+path,True)
|
||||||
gstreamer.close()
|
gstreamer.close()
|
||||||
gstreamer.load(path)
|
gstreamer.load(path)
|
||||||
|
|
||||||
|
|
||||||
|
def whatIs(self,id):
|
||||||
|
curlib = str( settings.get("curlib") )
|
||||||
|
selstr = "track.name,artist.name,album.name"
|
||||||
|
frmstr = "track,artist,album,libtrack"
|
||||||
|
whrstr = "track.artist=artist.id AND track.album=album.id"
|
||||||
|
whrstr += " AND libtrack.track=track.id AND libtrack.library="+curlib
|
||||||
|
sel = sql.Select(selstr, frmstr, whrstr)
|
||||||
|
result = sel.execute().fetchall()
|
||||||
|
|
||||||
|
#if len(result) <= id:
|
||||||
|
# return
|
||||||
|
result = result[id]
|
||||||
|
|
||||||
|
write(result[0])
|
||||||
|
write("By: "+result[1])
|
||||||
|
write("From: "+result[2])
|
||||||
|
|
||||||
|
|
||||||
|
def nowPlaying(self):
|
||||||
|
self.whatIs(settings.get("curtrk"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def run(self, args=None):
|
def run(self, args=None):
|
||||||
if args==None or len(args) < 1:
|
if args==None or len(args) < 1:
|
||||||
|
@ -37,6 +61,13 @@ class Plugin(plugin.Plugin):
|
||||||
if args[0] == "load":
|
if args[0] == "load":
|
||||||
self.loadTrack(args[1:])
|
self.loadTrack(args[1:])
|
||||||
|
|
||||||
|
elif args[0] == "whatis":
|
||||||
|
id = int(args[1])
|
||||||
|
self.whatIs(id)
|
||||||
|
|
||||||
|
elif args[0] == "now":
|
||||||
|
self.nowPlaying()
|
||||||
|
|
||||||
elif args[0] == "play":
|
elif args[0] == "play":
|
||||||
signal.emit("play")
|
signal.emit("play")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user