gst-trick-mode-looping-3.py: port to GStreamer 1.0
[experiments/gstreamer.git] / python / gst-looping-video-1.py
1 #!/usr/bin/env python
2
3 # Get a test sample with:
4 # youtube-dl -t http://www.youtube.com/watch?v=yWa-YXiSk2Y
5
6 import sys
7
8 import gobject
9 gobject.threads_init()
10
11 import gst
12
13
14 class Player:
15     def __init__(self, filename):
16         self._filename = filename
17
18         self._player = gst.element_factory_make("playbin2", "player")
19         self._player.set_property("uri", filename)
20
21         bus = self._player.get_bus()
22         bus.add_signal_watch()
23         bus.connect('message::eos', self.on_eos)
24
25     def run(self):
26         self._player.set_state(gst.STATE_PLAYING)
27         loop = gobject.MainLoop()
28         loop.run()
29
30     def on_eos(self, bus, msg):
31         sys.stderr.write(".")
32         self._player.seek_simple(gst.FORMAT_TIME, gst.SEEK_FLAG_FLUSH, 0)
33
34
35 def main(args):
36     def usage():
37         sys.stdout.write("usage: %s <URI-OF-MEDIA-FILE>\n" % args[0])
38
39     if len(args) != 2:
40         usage()
41         sys.exit(1)
42
43     if not gst.uri_is_valid(args[1]):
44         sys.stderr.write("Error: Invalid URI: %s\n" % args[1])
45         sys.exit(1)
46
47     player = Player(args[1])
48     player.run()
49
50 if __name__ == '__main__':
51     sys.exit(main(sys.argv))