python: update python examples to modern python, Gst, and Glib versions
[experiments/gstreamer.git] / python / gst-trick-mode-looping-2.py
index b3487dc..a398331 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 #
 # A simple "trick-mode" looping player.
 # Version 2, based on "about-to-finish" handling.
@@ -15,8 +15,7 @@ gi.require_version('Gst', '1.0')
 from gi.repository import Gst
 Gst.init(None)
 
-from gi.repository import GObject
-GObject.threads_init()
+from gi.repository import GLib
 
 
 class Player:
@@ -24,7 +23,7 @@ class Player:
         self._uri = uri
         self._rate = rate
 
-        self._player = Gst.ElementFactory.make("playbin", "player")
+        self._player = Gst.ElementFactory.make("playbin3", "player")
         self._player.set_property("uri", uri)
         self._player.connect("about-to-finish", self.on_about_to_finish)
 
@@ -35,7 +34,7 @@ class Player:
 
     def run(self):
         self._player.set_state(Gst.State.PLAYING)
-        self.loop = GObject.MainLoop()
+        self.loop = GLib.MainLoop()
         self.loop.run()
 
     def quit(self):
@@ -54,16 +53,16 @@ class Player:
 
     def on_error(self, bus, msg):
         (err, debug) = msg.parse_error()
-        print "Error: %s" % err, debug
+        print("Error: %s" % err, debug)
         self.quit()
 
     def on_state_changed(self, bus, msg):
         if msg.src != self._player:
             return
 
-        print 'on_state_changed'
+        print('on_state_changed')
         old_state, new_state, pending = msg.parse_state_changed()
-        print "%s -> %s" % (old_state, new_state)
+        print("%s -> %s" % (old_state, new_state))
         if old_state == Gst.State.READY and new_state == Gst.State.PAUSED:
             self.set_rate(self._rate)