New Gtk4 Gtk.Video() widget

Hi! It’s my first message here :slightly_smiling_face:

It’s been a while now that Gtk4 shipped out, with a new Gtk.Video()
component
to display a simple video in a Gtk window without resorting to using Gstreamer.

There were a lot of blog posts about it ; But no matter how hard I try, I can’t find a single example (? not even in C) of implementation ; I got as far as presenting the widget in a window (code here) but that’s it :frowning:

The window shows up, with a neat play button in the lower left corner, all signals are good, no warnings or messages in the console, but the video doesn’t play, the play button does nothing and the window stays black.

Am I missing something obvious? Like a library to install, anything?

Is there a single implementation example of this widget anywhere on the internet ?

try

import sys
import gi
gi.require_version('Gtk', '4.0')
from gi.repository import Gtk,Gio


class MainWindow(Gtk.ApplicationWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        
        self.app_ = self.get_application()
        self.set_default_size(800, 600)
        
        media_stream =  Gtk.MediaFile.new_for_filename("/home/yuceff28/Videos/untitled.mp4")
        video = Gtk.Video.new_for_media_stream(media_stream)
        video.set_autoplay(True)
        video.set_hexpand(True)
        video.set_vexpand(True)
        
        self.set_child(video)
                
class MyApp(Gtk.Application):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        
    def do_activate(self):
        active_window = self.props.active_window
        if active_window:
            active_window.present()
        else:
            self.win = MainWindow(application=self)
            self.win.present()

app = MyApp(application_id="com.github.yucefsourani.myapplicationexample",flags= Gio.ApplicationFlags.FLAGS_NONE)
app.run(sys.argv)

I dont why if i use Gtk.Video.new_for_filename() the program keep running after close window .

1 Like

Thanks a lot Youssef, but I just tried it and the same thing happened: Widget loads fine, but the video does not play ; I’m gonna try and find another machine but at least on this one (I’m on a Ubuntu 22 / Rapberry Pi 4 at the moment, and Gstreamer 1.n tools and libs work just fine) the implementation is broken, I’m guessing some libs are missing, I tried installing everything that has gtk4 in the name, but that didn’t help.

1 Like

Does that include libgtk-4-media-gstreamer?

2 Likes

Bingo ! That did it, thanks a lot Zander :slightly_smiling_face:

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