Connect to EOS with Gtk.Video()

Hi ;

Here is how I load / play a video file:

self.video = Gtk.Video()
# (...)
stream = Gtk.MediaFile.new_for_file(file)
self.video.set_media_stream(stream)
stream.play()

But how can I know when the video playback reaches the end of the stream? The MediaStream methods seem to be only “stateful”, that is, I would have to implement some sort of timeout to check if the stream is closed.

How to connect to this media_stream (or its underlying bus, because I know how to connect to a Gst pipeline bus eos signal) to fire a callback function on the “end of stream” signal?

try stream.connect(“notify::ended”,self.on_media_stream_ended)

1 Like

It works perfectly :slight_smile: thanks a lot, and may I add, where is this stream.connect() function documented? Shouldn’t it be at least somehow linked in the MediaStream class documentation? Also is there a list somewhere of all the possible signals to connect to?

After a month now of working with Gtk4 and searching for documentation, I really feel like something is missing. Is there a book I could buy? My only reference is the official documentation - that does not even mention Python - and the PyGObject API Reference (thank God for that BTW) but is there a Gtk4 Python documentation - ideally with examples, for complex new concepts like actions - planned?

1 Like

The “connect” method comes from GObject, in Python.

You’re looking at the C API reference. In C, there is no “connect” method: the function is called g_signal_connect().

It’s part of the API reference.

The “notify” signal is detailed: the name of the signal is “notify”, and the part after the :: separator is the name of a readable property—in this case, the “ended” property on the media stream object.

No, there are no books.

The GObject C documentation comes with a tutorial and an explanation of the type system concepts, including signals and properties. Of course, those are mostly for people who understand C.

Python documentation isn’t great, but any contribution there is very much welcome.

The GTK4 reference is available here: https://amolenaar.github.io/pgi-docgen/

You can find tutorials with Python code examples on the GNOME Developer Documentation website.

More documentation is always welcome, especially from new contributors. Everything you see is written and maintained by volunteers.

2 Likes

Those two last links are basically what I have been looking for, thank you very much.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.