3 # A simple looping player.
4 # Version 1, based on EOS 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):
22 self._player = Gst.ElementFactory.make("playbin", "player")
23 self._player.set_property("uri", uri)
25 bus = self._player.get_bus()
26 bus.add_signal_watch()
27 bus.connect('message::eos', self.on_eos)
28 bus.connect('message::error', self.on_error)
31 self._player.set_state(Gst.State.PLAYING)
32 self.loop = GObject.MainLoop()
36 self._player.set_state(Gst.State.NULL)
39 def on_eos(self, bus, msg):
41 self._player.seek_simple(Gst.Format.TIME, Gst.SeekFlags.FLUSH, 0)
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))