Is it possible in PyQt4
to embed a video via mpylayer
into a QWidget
(or into a subclass of it). If so, could you provide a minimal working example.
Asked
Active
Viewed 3,343 times
2 Answers
3
For a complete example of a Qt Widget that embeds MPlayer, try qmpwidget.
But here's a minimal PyQt demo to get you started:
import mpylayer
from PyQt4 import QtGui, QtCore
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.container = QtGui.QWidget(self)
self.container.setStyleSheet('background: black')
self.button = QtGui.QPushButton('Open', self)
self.button.clicked.connect(self.handleButton)
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.container)
layout.addWidget(self.button)
self.mplayer = mpylayer.MPlayerControl(
'mplayer', ['-wid', str(self.container.winId())])
def handleButton(self):
path = QtGui.QFileDialog.getOpenFileName()
if not path.isEmpty():
self.mplayer.loadfile(unicode(path))
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.resize(640, 480)
window.show()
sys.exit(app.exec_())
(NB: this demo has only been tested on Linux)

ekhumoro
- 115,249
- 20
- 229
- 336
-
@student. Totally missed that you were using `mpylayer`. Anyway, I have updated my demo script accordingly. – ekhumoro Aug 13 '12 at 21:47
-
Can it be done without `mpylayer`? maybe using `PyQt4.phonon` ? – mrgloom Apr 06 '16 at 18:08
-
@mrgloom. Not exactly sure what you mean, but the [original version of my answer](http://stackoverflow.com/revisions/11939294/1) doesn't use `mpylayer`. – ekhumoro Apr 06 '16 at 18:30
1
You have to get the handle (id) of the widget → http://qt-project.org/doc/qt-4.8/qwidget.html#winId
And pass it to the -wid
option of the MPlayer.
I can't provide you an example with Qt, simply because I don't know Qt, but I already wrote an MplayerCtrl for wxPython: https://bitbucket.org/dav1d/mplayerctrl
Relevant Code: https://bitbucket.org/dav1d/mplayerctrl/src/c680a1d99ad2/MplayerCtrl.py#cl-873

dav1d
- 5,917
- 1
- 33
- 52
-
Thanks for the hints. But I need more details. Perhaps someone with PyQt knowledge can add a minimal example – student Aug 13 '12 at 09:25