[gst-devel] Playbin Element Hanging GUI and MainLoop
Mystilleef
mystilleef at gmail.com
Fri May 11 02:53:19 CEST 2007
Hello,
How do I prevent a Playbin element from blocking the GUI or mainloop
when changing its state to PAUSE/PLAYING? In particular, I'm having
problems streaming some URIs that makes the playbin block the GUI and
mainloop. I attached a test code you can run to reproduce the problem.
The code has a good stream (self.__nice_stream) and bad stream
(self.__bad_stream). You can change these streams in the
self.__play_uri() method.
Thanks
To run the code type
python test.py
File test.py
========================================================================
class MyPlayBin(object):
def __init__(self):
self.__init_attributes()
self.__arrange_widgets()
self.__window.connect("delete-event", self.__delete_event_cb)
self.__play_button.connect("clicked", self.__clicked_play_button_cb)
self.__stop_button.connect("clicked", self.__clicked_stop_button_cb)
self.__window.show_all()
def __init_attributes(self):
self.__bad_stream = "http://66.250.45.118:7204"
self.__nice_stream = "http://scfire-ntc0l-2.stream.aol.com:80/stream/1074"
from gst import element_factory_make
self.__element = element_factory_make("playbin", "MainPipeline")
self.__bus = self.__element.get_bus()
self.__bus.add_signal_watch()
self.__bus.connect("message::buffering", self.__buffering_cb)
from gtk import Window, Label, Button
from gtk import STOCK_MEDIA_PLAY, STOCK_MEDIA_PAUSE
self.__label = Label("READY")
self.__play_button = Button(stock=STOCK_MEDIA_PLAY)
self.__stop_button = Button(stock=STOCK_MEDIA_PAUSE)
self.__window = Window()
return
def __play_uri(self):
self.__stop()
self.__label.set_text("Preparing to play")
from gst import STATE_PAUSED
self.__element.set_property("uri", self.__bad_stream)
self.__element.set_state(STATE_PAUSED)
return False
def __stop(self):
from gst import STATE_NULL, STATE_READY
self.__element.set_state(STATE_READY)
self.__element.set_state(STATE_NULL)
self.__label.set_text("Paused")
return
def __buffering_cb(self, bus, data):
from gst import STATE_PAUSED, STATE_PLAYING
percentage = data.structure["buffer-percent"]
if percentage == 100:
self.__element.set_state(STATE_PLAYING)
self.__label.set_text("Playing")
else:
self.__element.set_state(STATE_PAUSED)
message = "%s buffering..." % percentage
self.__label.set_text(message)
return
def __arrange_widgets(self):
self.__window.set_title("MyPlayBin")
self.__window.set_border_width(10)
from gtk import VBox, HBox
vbox = VBox(spacing=10)
hbox = HBox(spacing=20)
self.__window.add(vbox)
vbox.pack_start(self.__label, True, True, 0)
vbox.pack_start(hbox)
hbox.pack_start(self.__play_button, True, True, 0)
hbox.pack_start(self.__stop_button, True, True, 0)
return
def __clicked_play_button_cb(self, *args):
self.__play_uri()
return False
def __clicked_stop_button_cb(self, *args):
self.__stop()
return False
def __delete_event_cb(self, *args):
raise SystemExit
return True
if __name__ == "__main__":
from gobject import threads_init, MainLoop
threads_init()
MyPlayBin()
MainLoop().run()
========================================================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.py
Type: text/x-python
Size: 2535 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20070511/98832bb0/attachment.py>
More information about the gstreamer-devel
mailing list