ges-cut-clip.sh: user bash in the shebang line
[experiments/gstreamer.git] / python / gst-trick-mode-looping-1.py
index b1fedb3..5a14848 100755 (executable)
@@ -41,12 +41,7 @@ class Player:
 
     def on_eos(self, bus, msg):
         sys.stderr.write(".")
-        seek_event = Gst.Event.new_seek(self._rate,
-                                        Gst.Format.TIME,
-                                        Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE,
-                                        Gst.SeekType.SET, 0,
-                                        Gst.SeekType.NONE, 0)
-        self._player.send_event(seek_event)
+        self.set_seek(0)
 
     def on_error(self, bus, msg):
         (err, debug) = msg.parse_error()
@@ -66,17 +61,27 @@ class Player:
     def set_rate(self, rate):
         self._rate = rate
         position = self._player.query_position(Gst.Format.TIME)[1]
+        self.set_seek(position)
 
-        # Create the seek event
-        seek_event = Gst.Event.new_seek(rate,
-                                        Gst.Format.TIME,
-                                        Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE,
-                                        Gst.SeekType.SET, position,
-                                        Gst.SeekType.SET, -1)
+    def set_seek(self, position):
+        flags = Gst.SeekFlags.SKIP | Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE
+
+        if self._rate >= 0:
+            seek_event = Gst.Event.new_seek(self._rate,
+                                            Gst.Format.TIME,
+                                            flags,
+                                            Gst.SeekType.SET, position,
+                                            Gst.SeekType.NONE, 0)
+        else:
+            seek_event = Gst.Event.new_seek(self._rate,
+                                            Gst.Format.TIME,
+                                            flags,
+                                            Gst.SeekType.NONE, 0,
+                                            Gst.SeekType.END, position)
 
         if seek_event:
             self._player.send_event(seek_event)
-            Gst.info("rate set to %s" % rate)
+            Gst.info("rate set to %s" % self._rate)
         else:
             Gst.warining("change rate failed")