Add gst-raiplay-download.sh
[experiments/gstreamer.git] / python / gst-trick-mode-looping-3.py
index 6b406ea..1fef9d3 100755 (executable)
@@ -43,10 +43,7 @@ class Player:
         self.loop.quit()
 
     def on_segment_done(self, bus, msg):
-        self._player.seek(self._rate, Gst.Format.TIME,
-                          Gst.SeekFlags.SEGMENT | Gst.SeekFlags.SKIP | Gst.SeekFlags.ACCURATE,
-                          Gst.SeekType.SET, 0,
-                          Gst.SeekType.END, 0)
+        self.set_seek(0)
 
     def on_error(self, bus, msg):
         (err, debug) = msg.parse_error()
@@ -65,16 +62,32 @@ class Player:
 
     def set_rate(self, rate):
         self._rate = rate
+        self.set_seek(0, True)
 
-        if rate == 0:
-            self._player.set_state(Gst.State.PAUSED)
+    def set_seek(self, position, flush=False):
+        flags = Gst.SeekFlags.SEGMENT | Gst.SeekFlags.SKIP | Gst.SeekFlags.ACCURATE
+
+        if flush:
+            flags |= Gst.SeekFlags.FLUSH
+
+        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" % self._rate)
         else:
-            self._player.set_state(Gst.State.PLAYING)
-            self._player.seek(rate,
-                              Gst.Format.TIME,
-                              Gst.SeekFlags.SEGMENT | Gst.SeekFlags.SKIP | Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE,
-                              Gst.SeekType.SET, 0,
-                              Gst.SeekType.END, 0)
+            Gst.warining("change rate failed")
 
 
 def main(args):