I'd like to open a mov file in my PyQt application with a Quicktime-like player.
I am trying to use the phonon module but somehow I can't get it to work.
In my ui file (generated by Qt designer) it is initialized like this :
self.videoPlayer = phonon.Phonon.VideoPlayer(self.gridLayoutWidget)
self.videoPlayer.setObjectName(_fromUtf8("videoPlayer"))
And in my code I try this :
media_source = phonon.Phonon.MediaSource("path\\to\\my\\media.mov")
self.ui.videoPlayer.load(media_source)
self.ui.videoPlayer.play()
Can someone point me out where I'm doing something wrong ?
I don't see anything obviously wrong with the code you posted. If your system has the necessary codecs available, there's no reason why phonon shouldn't be able to play quicktime files.
Below is a simple phonon demo that plays quicktime files for me (on Linux, using the GStreamer backend). The demo also lists all the available mime-types that the current phonon backend can handle. On my system, the mime-type "video/quicktime" is shown in the list.
If you run it in a console, it will also print out any phonon error messages.
EDIT
It appears that, on windows, phonon may use Windows Media Player as the backend. If so, then it may be necessary to install some extra codecs for WMP so that it can play quicktime files.
from PyQt4 import QtGui, QtCore
from PyQt4.phonon import Phonon
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.media = Phonon.MediaObject(self)
self.media.stateChanged.connect(self.handleStateChanged)
self.video = Phonon.VideoWidget(self)
self.video.setMinimumSize(400, 400)
self.audio = Phonon.AudioOutput(Phonon.VideoCategory, self)
Phonon.createPath(self.media, self.audio)
Phonon.createPath(self.media, self.video)
self.button = QtGui.QPushButton('Choose File', self)
self.button.clicked.connect(self.handleButton)
self.list = QtGui.QListWidget(self)
self.list.addItems(Phonon.BackendCapabilities.availableMimeTypes())
layout = QtGui.QVBoxLayout(self)
layout.addWidget(self.video, 1)
layout.addWidget(self.button)
layout.addWidget(self.list)
def handleButton(self):
if self.media.state() == Phonon.PlayingState:
self.media.stop()
else:
path = QtGui.QFileDialog.getOpenFileName(self, self.button.text())
if path:
self.media.setCurrentSource(Phonon.MediaSource(path))
self.media.play()
def handleStateChanged(self, newstate, oldstate):
if newstate == Phonon.PlayingState:
self.button.setText('Stop')
elif (newstate != Phonon.LoadingState and
newstate != Phonon.BufferingState):
self.button.setText('Choose File')
if newstate == Phonon.ErrorState:
source = self.media.currentSource().fileName()
print ('ERROR: could not play:', source.toLocal8Bit().data())
print (' %s' % self.media.errorString().toLocal8Bit().data())
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('Phonon Player')
window = Window()
window.show()
sys.exit(app.exec_())