我正在构建一个基于PySide/Qt的应用程序,可以播放视频。我找到了mpv player和有用的python-mpv
库,将其放入基于Python的应用程序中。一切都很好。我遇到的问题是试图在Windows机器上使用播放器(在OS X上没有问题):播放器渲染,视频开始播放,声音正常,但我无法单击屏幕上的控件。控件是可见的,但单击它们什么也不做。就好像小部件没有收到鼠标点击,而只是在Windows上
我在互联网上找不到其他的东西来调试这个。玩家不会抛出错误或警告,因此很难知道从哪里开始。我通常也不是一个Windows迷This person seems to have had the same issue,但我不确定他们是否解决了这个问题
是否有其他人在让mpv播放器在基于Qt的应用程序中工作时遇到困难或成功?感谢您的真知灼见!与我在下面使用的代码相同:
#!/usr/bin/env python3
import os
# In order to load mpv-1.dll
os.environ["PATH"] = os.path.dirname(__file__) + os.pathsep + os.environ["PATH"]
import mpv
import sys
from PySide2.QtWidgets import *
from PySide2.QtCore import *
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())),
input_default_bindings=True,
input_vo_keyboard=True)
player.play('./sample-mp4-file.mp4')
if __name__ == '__main__':
# 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')
app = QApplication(sys.argv)
win = Test()
win.setFixedWidth(1200)
win.setFixedHeight(800)
win.show()
sys.exit(app.exec_())
我有这个问题,这是我的解决方案。您可以从mpv获取“鼠标按钮”事件并调用函数
相关问题 更多 >
编程相关推荐