I'm building a PySide/Qt based app that with video playback. I found mpv player and the helpful python-mpv
library to get it into my Python based app. Everything works great. The issue I'm having is trying to use the player on a Windows machine (no issues on OS X): the player renders, the video starts playing, the sound works, but I cannot CLICK on the on-screen controls. The controls are visible, but clicking on them does nothing. It's as if the widget isn't receiving the mouse clicks, but only on Windows?
I haven't found much else around the internets trying to debug this. The player throws no errors or warnings, so it's hard to know where to start. I'm not normally a Windows dude, either. This person seems to have had the same issue, but I'm not sure if they ever solved it.
Has anyone else had trouble or success getting mpv player to work inside a Qt-based app? Appreciate any insights! Same code I've been playing with below:
#!/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_())