gst-trick-mode.py: handle EOS and error conditions
authorAntonio Ospite <ao2@ao2.it>
Wed, 17 Sep 2014 11:36:34 +0000 (13:36 +0200)
committerAntonio Ospite <ao2@ao2.it>
Wed, 17 Sep 2014 11:44:02 +0000 (13:44 +0200)
python/gst-trick-mode.py

index 45e7af2..833892b 100755 (executable)
@@ -25,12 +25,26 @@ class Player:
 
         bus = self._player.get_bus()
         bus.add_signal_watch()
 
         bus = self._player.get_bus()
         bus.add_signal_watch()
+        bus.connect('message::eos', self.on_eos)
+        bus.connect('message::error', self.on_error)
         bus.connect('message::state-changed', self.on_state_changed)
 
     def run(self):
         self._player.set_state(Gst.State.PLAYING)
         bus.connect('message::state-changed', self.on_state_changed)
 
     def run(self):
         self._player.set_state(Gst.State.PLAYING)
-        loop = GObject.MainLoop()
-        loop.run()
+        self.loop = GObject.MainLoop()
+        self.loop.run()
+
+    def quit(self):
+        self._player.set_state(Gst.State.NULL)
+        self.loop.quit()
+
+    def on_eos(self, bus, msg):
+        self.quit()
+
+    def on_error(self, bus, msg):
+        (err, debug) = msg.parse_error()
+        print "Error: %s" % err, debug
+        self.quit()
 
     def on_state_changed(self, bus, msg):
         if msg.src != self._player:
 
     def on_state_changed(self, bus, msg):
         if msg.src != self._player: