From ce57d081f81b6e2c4f546f3a6813fa37d1cb99c4 Mon Sep 17 00:00:00 2001 From: Cimbali Date: Tue, 2 Nov 2021 11:03:37 +0100 Subject: [PATCH] Ensure gst player is always ready --- pympress/media_overlays/gst_backend.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/pympress/media_overlays/gst_backend.py b/pympress/media_overlays/gst_backend.py index 93cc2e30..b129bae3 100644 --- a/pympress/media_overlays/gst_backend.py +++ b/pympress/media_overlays/gst_backend.py @@ -44,17 +44,14 @@ class GstOverlay(base.VideoOverlay): #: A :class:`~Gst.Playbin` to be play videos playbin = None - #: `str` holding the path to the current file - uri = None - def __init__(self, *args, **kwargs): - super(GstOverlay, self).__init__(*args, **kwargs) - # Create GStreamer playbin self.playbin = Gst.ElementFactory.make('playbin', None) self.sink = Gst.ElementFactory.make('gtksink', None) self.playbin.set_property('video-sink', self.sink) + super(GstOverlay, self).__init__(*args, **kwargs) + self.media_overlay.remove(self.movie_zone) self.media_overlay.pack_start(self.sink.props.widget, True, True, 0) self.media_overlay.reorder_child(self.sink.props.widget, 0) @@ -85,7 +82,8 @@ def set_file(self, filepath): Args: filepath (`pathlib.Path`): The path to the media file path """ - self.uri = filepath.as_uri() + self.playbin.set_property('uri', filepath.as_uri()) + self.playbin.set_state(Gst.State.READY) def mute(self, value): @@ -129,7 +127,6 @@ def do_play(self): Returns: `bool`: `True` iff this function should be run again (:func:`~GLib.idle_add` convention) """ - self.playbin.set_property('uri', self.uri) self.playbin.set_state(Gst.State.PLAYING) return False @@ -152,6 +149,7 @@ def do_stop(self): """ Stops playing in the backend player. """ self.playbin.set_state(Gst.State.NULL) + self.playbin.set_state(Gst.State.READY) return False