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 GObject
17 GObject.threads_init()
21 def __init__(self, uri):
23 self._player = Gst.ElementFactory.make("playbin", "player")
24 self._player.set_property("uri", uri)
25 self._player.connect("about-to-finish", self.on_about_to_finish)
27 bus = self._player.get_bus()
28 bus.add_signal_watch()
29 bus.connect('message::error', self.on_error)
32 self._player.set_state(Gst.State.PLAYING)
33 self.loop = GObject.MainLoop()
37 self._player.set_state(Gst.State.NULL)
40 def on_about_to_finish(self, player):
42 player.set_property("uri", self._uri)
44 def on_error(self, bus, msg):
45 (err, debug) = msg.parse_error()
46 print "Error: %s" % err, debug
52 sys.stdout.write("usage: %s <filename>\n" % args[0])
58 uri = Gst.filename_to_uri(args[1])
63 if __name__ == '__main__':
64 sys.exit(main(sys.argv))