X-Git-Url: https://git.ao2.it/vidi-player.git/blobdiff_plain/81266999b597eeac96b846034444f4b240da72bb..d2933a9ba8a8813900e05b4051b625180b01958c:/vidi/Player.py diff --git a/vidi/Player.py b/vidi/Player.py index 26a9832..cf30f9f 100755 --- a/vidi/Player.py +++ b/vidi/Player.py @@ -30,6 +30,10 @@ 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) + self.mainloop = GObject.MainLoop() @staticmethod @@ -37,25 +41,14 @@ class Player(object): pipeline = Gst.parse_launch(pipeline_string) return Player(pipeline) - def quit(self): - self.mainloop.quit() - self.pipeline.set_state(Gst.State.NULL) - def bus_message_cb(self, unused_bus, message): if message.type == Gst.MessageType.EOS: - self.quit() + self.stop() def play(self): - bus = self.pipeline.get_bus() - bus.add_signal_watch() - bus.connect("message", self.bus_message_cb) - self.pipeline.set_state(Gst.State.PLAYING) + self.mainloop.run() - try: - self.mainloop.run() - except KeyboardInterrupt: - self.quit() - return 1 - - return 0 + def stop(self): + self.mainloop.quit() + self.pipeline.set_state(Gst.State.NULL)