X-Git-Url: https://git.ao2.it/vidi-player.git/blobdiff_plain/9a8f764328f6b47707ed24acc9a5e2fc9a4fcf57..8feb3b634207bd2176c686ce927a6e037460d7f7:/vidi/Player.py diff --git a/vidi/Player.py b/vidi/Player.py index 58c3ece..d2eacef 100755 --- a/vidi/Player.py +++ b/vidi/Player.py @@ -30,9 +30,11 @@ GObject.threads_init() class Player(object): def __init__(self, pipeline): self.pipeline = pipeline + bus = self.pipeline.get_bus() bus.add_signal_watch() - bus.connect("message", self.bus_message_cb) + bus.connect("message::eos", self.on_eos) + bus.connect('message::error', self.on_error) self.mainloop = GObject.MainLoop() @@ -41,21 +43,18 @@ class Player(object): pipeline = Gst.parse_launch(pipeline_string) return Player(pipeline) - def stop(self): - self.mainloop.quit() - self.pipeline.set_state(Gst.State.NULL) + def on_eos(self, bus, message): + self.stop() - def bus_message_cb(self, unused_bus, message): - if message.type == Gst.MessageType.EOS: - self.stop() + def on_error(self, bus, msg): + (err, debug) = msg.parse_error() + print("Error: %s" % err) + self.stop() def play(self): self.pipeline.set_state(Gst.State.PLAYING) + self.mainloop.run() - try: - self.mainloop.run() - except KeyboardInterrupt: - self.stop() - return 1 - - return 0 + def stop(self): + self.mainloop.quit() + self.pipeline.set_state(Gst.State.NULL)