Skip to content

Commit

Permalink
Ensure gst player is always ready
Browse files Browse the repository at this point in the history
  • Loading branch information
Cimbali committed Nov 2, 2021
1 parent 88acc7a commit ce57d08
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions pympress/media_overlays/gst_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit ce57d08

Please sign in to comment.