Is it just me or is QMediaplayer not working properly?

I started to work on a mediaplayer a while ago and started learning PyQT and all that is going good. But I noticed that when you are using QMediaplayer the .duration() function is completly wrong all mp3 files that are loaded give a time that is way longer then it is supposed to be. I also noticed that not all audio files are loaded or even working with the Qmediaplayer while other python modules work fine with them. To give you an example go and look at the failamp mediaplayer that you can find on this site. I really hope this gets fixed because now I’m forced to use python VLC module or other audio modules in python and it’s not an easy task to implement it because of the poor documentation there is. Besides this issue PyQt is really good for making GUI’s in python hope to hear something about this issue soon!

It’s not just you, there is something very odd with Qt Mediaplayer on Windows. But I just had a look into it and there seems to be a solution.

In the Qt documentation on Windows multimedia it mentions that there are two plugins that can be used on Windows – directshow or windowsmediafoundation.

The DirectShow backend is the legacy one, but seems for some reason to be selected by default (documentation suggests it could be because of the need for a camera backend). If you switch to windowsmediafoundation instead, you get accurate duration reporting and better media file support.

To enable it, just add the following to your application, somewhere before you create the QApplication instance.

import os
os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = 'windowsmediafoundation'
1 Like

Thank you! It works way better now, to bad I didn’t ask it sooner!