X-Git-Url: https://git.ao2.it/experiments/gstreamer.git/blobdiff_plain/1a730f925f38fa0b45bbc1a95a6b03e296d1f6d8..6951c082f65a3f3d02be9536bdb058e8747f5767:/python/gst-trick-mode.py diff --git a/python/gst-trick-mode.py b/python/gst-trick-mode.py index 0bb5877..43cd8f4 100755 --- a/python/gst-trick-mode.py +++ b/python/gst-trick-mode.py @@ -25,12 +25,26 @@ class Player: 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) - 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: @@ -52,16 +66,16 @@ class Player: # Create the seek event if rate > 0: seek_event = Gst.Event.new_seek(rate, - Gst.Format.TIME, - Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, - Gst.SeekType.SET, position, - Gst.SeekType.NONE, 0) + Gst.Format.TIME, + Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, + Gst.SeekType.SET, position, + Gst.SeekType.NONE, 0) else: seek_event = Gst.Event.new_seek(rate, - Gst.Format.TIME, - Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, - Gst.SeekType.SET, 0, - Gst.SeekType.SET, position) + Gst.Format.TIME, + Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, + Gst.SeekType.SET, 0, + Gst.SeekType.SET, position) if seek_event: self._player.send_event(seek_event) @@ -72,15 +86,16 @@ class Player: def main(args): def usage(): - sys.stdout.write("usage: %s \n" % args[0]) + sys.stdout.write("usage: %s \n" % args[0]) - if len(args) != 2: + if len(args) != 3: usage() sys.exit(1) uri = Gst.filename_to_uri(args[1]) + rate = float(args[2]) - player = Player(uri, 3.0) + player = Player(uri, rate) player.run() if __name__ == '__main__':