我使用库https://github.com/jaseg/python-mpv来控制 mpv 播放器,但是当它与 pyside6 一起使用时,键绑定不起作用(播放器不完全接受输入)。我究竟做错了什么?还是嵌入pyside6时无法使用它们?(如果我在没有嵌入的情况下使用相同的参数运行播放器,一切正常)
import os
os.add_dll_directory(os.getcwd())
import mpv
from PySide6.QtWidgets import *
from PySide6.QtCore import *
mpvfolderpath = f"mpv.net/portable_config/"
import sys
class Test(QMainWindow):
def __init__(self, parent=None):
super().__init__(parent)
self.container = QWidget(self)
self.setCentralWidget(self.container)
self.container.setAttribute(Qt.WA_DontCreateNativeAncestors)
self.container.setAttribute(Qt.WA_NativeWindow)
player = mpv.MPV(wid=str(int(self.container.winId())),
vo="gpu", # You may not need this
log_handler=print,
loglevel='debug',
input_default_bindings=True,
input_vo_keyboard=True)
@player.on_key_press('f')
def my_f_binding():
print("f работает!")
player.play('test.mp4')
app = QApplication(sys.argv)
# This is necessary since PyQT stomps over the locale settings needed by libmpv.
# This needs to happen after importing PyQT before creating the first mpv.MPV instance.
import locale
locale.setlocale(locale.LC_NUMERIC, 'C')
win = Test()
win.show()
sys.exit(app.exec_())