Gtk4中Gtk.Video()组件无法播放视频的问题求助
Gtk4 Video组件无法播放视频的问题
Gtk4发布已有一段时间,它新增了**Gtk.Video()**组件,无需依赖Gstreamer即可在Gtk窗口中显示视频。这是一个非常简洁的类,仅有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)
窗口能正常显示,左下角有播放按钮,控制台无警告或错误信息,但视频无法播放,点击播放按钮也无反应,窗口始终为黑屏。
请问我是否遗漏了什么关键步骤?
内容的提问来源于stack exchange,提问作者yPhil
相关产品推荐
相关产品推荐

