About Signaling

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

About Signaling

Zhanhua Kuang
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


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: About Signaling

Tim-Philipp Müller-2
On Mon, 2008-03-10 at 14:50 +0800, Zhanhua Kuang wrote:

>   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.

bus.add_signal_watch() only works if you run a GLib/Gtk main loop.

Also note that "file://" + file_path is not really the right way to
create an URI from a file name.

Cheers
 -Tim



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel
Reply | Threaded
Open this post in threaded view
|

Re: About Signaling

Zhanhua Kuang
Thank you very much...
On Mon, 2008-03-10 at 09:00 +0000, Tim Müller wrote:

> On Mon, 2008-03-10 at 14:50 +0800, Zhanhua Kuang wrote:
>
> >   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.
>
> bus.add_signal_watch() only works if you run a GLib/Gtk main loop.
>
> Also note that "file://" + file_path is not really the right way to
> create an URI from a file name.
>
> Cheers
>  -Tim
>
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> gstreamer-devel mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/gstreamer-devel


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
gstreamer-devel mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gstreamer-devel