【问题标题】:Gtk4 Gtk.Video() doesn't playGtk4 Gtk.Video() 不播放
【发布时间】:2022-11-03 00:43:30
【问题描述】:

Gtk4 发布已经有一段时间了,a new Gtk.Video() component 允许在 Gtk 窗口中显示视频,而无需使用 Gstreamer。

这是一个very simple class,只有少数子类 (4) 方法 (10) 和属性 (2)。

但是无论我多么努力,我都找不到一个例子(?甚至在 C 中也没有);我走了这么远:

#!/usr/bin/env python3

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

class MainWindow(Gtk.ApplicationWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(title="Mini Player", *args, **kwargs)
        player = Gtk.Video.new()
        player.set_autoplay(True)
        print('file: ', player.props.file) # => None
        file_to_play = Gio.File.new_for_path('/my/valid/video/file.mp4')
        player.set_file(file_to_play) # => this is supposed to start the playing
        self.set_child(player)
        print('file: ', player.props.file) # => file: __gi__.GLocalFile object
        print('autoplay: ', player.props.autoplay) # => True
        # self.show() # I tried this too, it does nothing
        
class MyApp(Adw.Application):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.connect('activate', self.on_activate)
        self.connect('open', self.on_open)
        self.set_flags(Gio.ApplicationFlags.HANDLES_OPEN)  # Need to tell GApplication we can handle this
        self.win = None
        
    def on_activate(self, app):
        self.win = MainWindow(application=app)
        self.win.present()
    
    # This is to avoid the error "Your application claims to support opening files but does not implement g_application_open() and has no handlers connected to the 'open' signal." while I learn how to pass this file to the Mainwindow class
    def on_open(self, app, files, n_files, hint):
        self.on_activate(app)
        for file in files:
            print("File to open: " + file.get_path())  
            
app = MyApp(application_id="com.example.GtkApplication")
app.run(sys.argv)

窗口出现,左下角有一个整洁的播放按钮,所有信号都很好,控制台中没有警告或消息,但视频不播放,播放按钮没有任何作用,窗口保持黑色。

我错过了一些明显的东西吗?

【问题讨论】:

    标签: python video gtk4


    【解决方案1】:

    好的,I found out 我错过了一个图书馆:

    sudo apt install libgtk-4-media-gstreamer
    

    Dit the trick,它现在可以工作了。它非常慢,但它有效。

    【讨论】:

      猜你喜欢
      • 2022-07-12
      • 1970-01-01
      • 2015-09-20
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-13
      • 1970-01-01
      相关资源
      最近更新 更多