diff --git a/lazy_player/thumbnailer.py b/lazy_player/thumbnailer.py index 2bf52e2..ed27715 100644 --- a/lazy_player/thumbnailer.py +++ b/lazy_player/thumbnailer.py @@ -7,6 +7,8 @@ from gi.repository import Gst from .file_model import FileItem +DEFAULT_SEEK_FLAGS = Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT + class Thumbnailer(threading.Thread): queue: Queue[FileItem | None] @@ -84,11 +86,7 @@ class Thumbnailer(threading.Thread): return seek_pos = duration // 3 - pipeline.seek_simple( - Gst.Format.TIME, - Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, - seek_pos, - ) + pipeline.seek_simple(Gst.Format.TIME, DEFAULT_SEEK_FLAGS, seek_pos) # Start playing to capture frame pipeline.set_state(Gst.State.PLAYING) diff --git a/lazy_player/video_player.py b/lazy_player/video_player.py index 50f5277..4f759a6 100644 --- a/lazy_player/video_player.py +++ b/lazy_player/video_player.py @@ -4,6 +4,8 @@ from pathlib import Path from gi.repository import GObject, Gst, Gtk +DEFAULT_SEEK_FLAGS = Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT + class VideoPlayer(GObject.Object): pipeline: Gst.Pipeline @@ -65,11 +67,7 @@ class VideoPlayer(GObject.Object): if position: # Seek to saved position - self.pipeline.seek_simple( - Gst.Format.TIME, - Gst.SeekFlags.FLUSH | Gst.SeekFlags.ACCURATE, - position, - ) + self.pipeline.seek_simple(Gst.Format.TIME, DEFAULT_SEEK_FLAGS, position) # Start playing self.pipeline.set_state(Gst.State.PLAYING) @@ -102,29 +100,17 @@ class VideoPlayer(GObject.Object): if new_pos < 0: new_pos = 0 - self.pipeline.seek_simple( - Gst.Format.TIME, - Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, - new_pos, - ) + self.pipeline.seek_simple(Gst.Format.TIME, DEFAULT_SEEK_FLAGS, new_pos) def seek_start(self): """Seek to the start of the video.""" - self.pipeline.seek_simple( - Gst.Format.TIME, - Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, - 0, - ) + self.pipeline.seek_simple(Gst.Format.TIME, DEFAULT_SEEK_FLAGS, 0) def seek_end(self): """Seek to the end of the video.""" duration = self.get_duration() if duration: - self.pipeline.seek_simple( - Gst.Format.TIME, - Gst.SeekFlags.FLUSH | Gst.SeekFlags.KEY_UNIT, - duration, - ) + self.pipeline.seek_simple(Gst.Format.TIME, DEFAULT_SEEK_FLAGS, duration) def get_position(self) -> int | None: """Get current playback position in nanoseconds"""