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 GLib
20 def __init__(self, uri):
21 self._player = Gst.ElementFactory.make("playbin", "player")
22 self._player.set_property("uri", uri)
24 bus = self._player.get_bus()
25 bus.add_signal_watch()
26 bus.connect('message::eos', self.on_eos)
27 bus.connect('message::error', self.on_error)
30 self._player.set_state(Gst.State.PLAYING)
31 self.loop = GLib.MainLoop()
35 self._player.set_state(Gst.State.NULL)
38 def on_eos(self, bus, msg):
40 self._player.seek_simple(Gst.Format.TIME, Gst.SeekFlags.FLUSH, 0)
42 def on_error(self, bus, msg):
43 (err, debug) = msg.parse_error()
44 print("Error: %s" % err, debug)
50 sys.stdout.write("usage: %s <filename>\n" % args[0])
56 uri = Gst.filename_to_uri(args[1])
61 if __name__ == '__main__':
62 sys.exit(main(sys.argv))