3 # A simple looping player.
4 # Version 2, based on "about-to-finish" handling.
6 # Get a test sample with:
7 # youtube-dl -t http://www.youtube.com/watch?v=yWa-YXiSk2Y
12 gi.require_version('Gst', '1.0')
13 from gi.repository import Gst
16 from gi.repository import GLib
20 def __init__(self, uri):
22 self._player = Gst.ElementFactory.make("playbin3", "player")
23 self._player.set_property("uri", uri)
24 self._player.connect("about-to-finish", self.on_about_to_finish)
26 bus = self._player.get_bus()
27 bus.add_signal_watch()
28 bus.connect('message::error', self.on_error)
31 self._player.set_state(Gst.State.PLAYING)
32 self.loop = GLib.MainLoop()
36 self._player.set_state(Gst.State.NULL)
39 def on_about_to_finish(self, player):
41 player.set_property("uri", self._uri)
43 def on_error(self, bus, msg):
44 (err, debug) = msg.parse_error()
45 print("Error: %s" % err, debug)
51 sys.stdout.write("usage: %s <filename>\n" % args[0])
57 uri = Gst.filename_to_uri(args[1])
62 if __name__ == '__main__':
63 sys.exit(main(sys.argv))