[gst-devel] About Signaling
Zhanhua Kuang
zkuang82 at gmail.com
Mon Mar 10 07:50:58 CET 2008
Hi,
I'm new to GST, also Python. And I'm trying to write a simple
command-line player with pygst. But I met some problems about signaling.
I expect the __on_message method would be called when the engine finish
playing a file. But at actually, it's never called.
This is what I wrote:
class Gs_Engin:
"The Gstreamer Engin for playing back everything."
def __init__(self):
self.playbin = gst.element_factory_make("playbin", "player")
self.signaled = 0
def gs_connect_signal(self, signal, callback):
if self.signaled == 0:
print 'connecting signal'
bus = self.playbin.get_bus()
bus.add_signal_watch()
self.signaled = 1
bus.connect(signal, callback)
print 'signal connected'
def gs_stop(self):
self.playbin.set_state(gst.STATE_NULL)
def gs_start(self, file_path):
self.playbin.set_property('uri', "file://" + file_path)
self.playbin.set_state(gst.STATE_PLAYING)
====================================================================
class gs_test:
def __init__(self):
self.gs_engin = Gs_Engin()
self.gs_engin.gs_connect_signal('message', self.__on_message)
def __on_message(self, bus, message):
print 'Signal Called'
t = message.type
if t == gst.MESSAGE_EOS:
self.gs_engin.gs_stop()
print 'Finish playing file.'
elif t == gst.MESSAGE_ERROR:
self.gs_engin.gs_stop()
print 'Error, maybe you input a wrong file.'
else:
print 'Unknown message'
def recv_input(self):
while 1 > 0:
command = raw_input('Input your command: ')
cmdparts = command.split()
if cmdparts == []:
continue
if command == 'stop':
self.gs_engin.gs_stop()
elif command == 'quit':
break
elif cmdparts[0] == 'play':
if os.path.exists(cmdparts[1]):
self.gs_engin.gs_start(cmdparts[1])
else:
print 'wrong command\n'
self.gs_engin.gs_stop()
print 'Quit\n'
if __name__ == "__main__":
test = gs_test()
test.recv_input()
I must miss something important, but I don't know what it is. Any advise
for this problem?
Thanks
--Zhanhua
More information about the gstreamer-devel
mailing list