If PySide Phonon not Displaying Video: Check This Out

nice try

nice try

When you spend over 6 hours on troubleshooting 3 lines of code…3 lines, yea…but it just didn’t work!

I’ve resumed work on my video app and I’ve had to trot between Django for the backend and PySide for the Desktop application.

It was time for me to implement a video playback feature – to allow users preview trailers of media. PySide has Phonon in the PySide.phonon package and according to documentation (https://srinikom.github.io/pyside-docs/PySide/phonon/Phonon.VideoPlayer.html), it was supposed to be

player = VideoPlayer(Phonon.VideoCategory, parentWidget)
player.finished.connect(player.deleteLater)
player.play(url)

Usually, the docs give you a snippet like the above and you then finish up the module or function. In short, you still need to look around. I’m basically racing against time, so I have too little of it to read through all the docs and refs…but I have google.

I came across dpitkevics’ https://github.com/dpitkevics/stream-ies/blob/master/widgets/video_player.py and https://github.com/nicoddemus/PySide-Examples/blob/master/examples/phonon/videoplayer.py, but no matter what I tried…I was basically clawing at a brick wall…and that wasn’t still all.

I then decided to look in the direction of the almighty VLC; embedding it into my program. My first resource was https://forum.videolan.org/viewtopic.php?t=72360, but that forum entry was from 2010. I knew, but I wasn’t going to give up.

I spent another 2 hours re-realizing that 5 years is a looong time in the software universe. While trying to get the code from the previous link to work on Python 3, I ran into http://stackoverflow.com/questions/15345692/libvlc-vlc-is-unable-to-open-the-mrl-c-users-public-videos-sample-videos-wild from 2013, but even
pythonapi.PyCObject_AsVoidPtrhad been deprecated in Python 3.2 and then I ran into the function below that does what it’s called.

def convert_capsule_to_int(capsule):
ctypes.pythonapi.PyCapsule_GetPointer.restype = ctypes.c_void_p
ctypes.pythonapi.PyCapsule_GetPointer.argtypes = [ctypes.py_object, ctypes.c_char_p]
return ctypes.pythonapi.PyCapsule_GetPointer(capsule, None)

Still, I was back to where I had started because I couldn’t (didn’t have the faith) figure out why I was getting audio without video, and why closing the widget still left the audio active…ctypes was already frightening me. I bailed!

Then my eye caught something…”For the rest, in my experience Phonon often has trouble finding the codecs needed to play videos on Windows…” from Junuxx at http://stackoverflow.com/questions/12686827/pyqt-playing-movie-files-in-phonon-player-qt4-9.

Of Course! I was running windows 10. Frankly, I’ve been waiting for something like this to happen – it only took 4 months. That spanking new Windows 10 was going to bite me one day…and it did.

I quickly installed the K-Lite Codec Pack from filehippo (http://filehippo.com/download_klite_codec_pack/).

While running the install, it was fixing broken codec registry thing (roxio et. al), identifying codecs and doing things…while I kept my fingers crossed. It was 11p.m.

Then the moment of truth came.

I ran the same code I had run all day long…AND IT WORKED. MY PLAYER WORKED!!

Whew! It was codec wahala…not phonon.

I hope you read this in time to save you a hell o’time. Drop a comment…let me know if this helped you.