From: Antonio Ospite Date: Wed, 17 Sep 2014 21:20:43 +0000 (+0200) Subject: gst-trick-mode-looping-1.py: fix looping with negative rates X-Git-Url: https://git.ao2.it/experiments/gstreamer.git/commitdiff_plain/812f9174c7d3d3f3265142e905d3964978d8e647 gst-trick-mode-looping-1.py: fix looping with negative rates --- diff --git a/python/gst-trick-mode-looping-1.py b/python/gst-trick-mode-looping-1.py index b1fedb3..5a14848 100755 --- a/python/gst-trick-mode-looping-1.py +++ b/python/gst-trick-mode-looping-1.py @@ -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")