pyqt Playing movie files in phonon player QT4.9
Don't forget to show()
the videoplayer. For the rest, in my experience Phonon often has trouble finding the codecs needed to play videos on Windows. Installing K-Lite codec pack might work in that situation.
Here's a self-contained example that does work for me (Windows Vista32, Python 2.6.5, PyQt 4.7.3).
import sys
from PyQt4 import QtCore, QtGui
from PyQt4.phonon import Phonon
app = QtGui.QApplication(sys.argv)
vp = Phonon.VideoPlayer()
media = Phonon.MediaSource('C:\\video.mp4')
vp.load(media)
vp.play()
vp.show()
sys.exit(app.exec_())
Edit:
Multiple people have recently commented that the above code no longer gives the desired behavior. I haven't worked with PyQt in ages, but I suspect that one of the updates might have changed Phonon functionality.
According to the commenters, vp.show()
now needs to be called before Phonon.MediaSource()
, i.e.:
...
vp = Phonon.VideoPlayer()
vp.show()
media = Phonon.MediaSource('C:\\video.mp4')
vp.load(media)
vp.play()
sys.exit(app.exec_())
Katherina
Updated on June 14, 2022Comments
-
Katherina about 2 years
I'm definitely in need of your help guys.. As in really. My laptop has been stolen and I didn't have a backup of my pyqt phonon video player that I made a year ago. I forgot how and what to do to recreate it.
I only know some key things to do for it to work. So please help me out.From what i can remember I need to
- Set backend capabilities (set phonon backend to windows media player?)
- Install the required codecs (which i dont have a copy of)
- Code the program (and sadly I forgot how to play a video)
If there's someone out there who have a working sample python videoplayer, can you please share it with me?
I'm trying it right now and my sample doesn't work at all
from PyQt4.phonon import Phonon media_source = phonon.Phonon.MediaSource("C:\\Sample.avi") self.ui.videoPlayer.load(media_source) self.ui.videoPlayer.play()
Please help me. And thank you very much to you guys.
I'm using python 2.6 and qt version 4.9. Now I'm coding on a virtual box windows XP
EDIT: got a following sample with this problem but.. having this error when loading a file.
"The Operation Cannot Be Performed Because the Pins Are Not Connected"
This maybe because I'm using a virtual box in Ubuntu?
-
rr- about 9 yearsYou should
show
the player before loading the media, otherwise it will show after it has played the movie. At least this is what happened in my case. -
mrgloom about 8 yearsAlso for me it not worked,
vp.show()
need to be beforemedia = Phonon.MediaSource('C:\\video.mp4')
and also window for some reason is seems have size 0. -
Junuxx about 8 years@mrgloom: I guess this may have changed in the past 4 years. Back in 2012, with PyQt 4.7, this worked fine. I'll update the answer.