gst-trick-mode.py: add a comment to explain what the code is supposed to do
[experiments/gstreamer.git] / python / gst-looping-video-2.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         self._player.connect("about-to-finish", self.on_about_to_finish)
21
22     def run(self):
23         self._player.set_state(gst.STATE_PLAYING)
24         loop = gobject.MainLoop()
25         loop.run()
26
27     def on_about_to_finish(self, player):
28         sys.stderr.write(".")
29         player.set_property("uri", self._filename)
30
31
32 def main(args):
33     def usage():
34         sys.stdout.write("usage: %s <URI-OF-MEDIA-FILE>\n" % args[0])
35
36     if len(args) != 2:
37         usage()
38         sys.exit(1)
39
40     if not gst.uri_is_valid(args[1]):
41         sys.stderr.write("Error: Invalid URI: %s\n" % args[1])
42         sys.exit(1)
43
44     player = Player(args[1])
45     player.run()
46
47 if __name__ == '__main__':
48     sys.exit(main(sys.argv))