<div dir="ltr">Hello,<br><br>I recently started using QMediaplayer to create a music player with PyQt (5.9.2) and noticed that the player duration is incorrect on files with "unusual" bitrates (e.g. 241 kbits/s). I found a similar question here <a href="https://forum.learnpyqt.com/t/is-it-just-me-or-is-qmediaplayer-not-working-properly/401">https://forum.learnpyqt.com/t/is-it-just-me-or-is-qmediaplayer-not-working-properly/401</a> and the answer suggests that the Direct Show back-end is causing this problem and recommend switching to Windows media foundation by running the following code:<div><br><div>```  <br>import os<br>os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = 'windowsmediafoundation'</div><div>```   </div><div><br>The problem is that I just can't manage to switch to windowsmediafoundation when running this code. I tried to insert it before calling QApplication() but nothing seems to be happening. See below an example of how I tried to implement the code :<br><br>```<br>import os<br># os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = 'windowsmediafoundation' I also tried to run it here<div><br>from PyQt5.QtWidgets import *<br>from PyQt5.QtCore import *<br>from PyQt5.QtMultimedia import *<br>import sys<br><br># os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = 'windowsmediafoundation' I also tried to run it here<br><br>class MainWindow(QMainWindow):<br>    def __init__(self, *args, **kwargs):<br>        super(MainWindow, self).__init__(*args, **kwargs)<br><br>        self.player = QMediaPlayer()<br>        self.player.durationChanged.connect(self.print_duration)<br>        self.player.setMedia(QMediaContent(QUrl.fromLocalFile(path_to_file)))<br>        self.show()<br><br>    def print_duration(self, duration):<br>        print(duration)<br><br>if __name__ == "__main__":<br><br>    os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = 'windowsmediafoundation' #This is where I tried to run it first<br><br>    app = QApplication(sys.argv)<br><br>    # os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = 'windowsmediafoundation' I also tried to run it here<br><br>    window = MainWindow()<br>    app.exec_()</div><div>```   </div><div><br>Indeed the duration bug is still present. Furthermore, when I go into the Library\plugins\mediaservice directory of my Anaconda installation, both the dsengine.dll and wmfengine.dll are present and trying to delete the dsengine.dll while running my music player app results in an error because dsengine.dll is being used by Python. wmfengine.dll on the other hand, can be deleted without such error. Hence, Direct Show is still being preferred by QtMultimedia.<br><br>It could be that I'm not using QT_MULTIMEDIA_PREFERRED_PLUGINS correctly, how can I switch the mediaservice to wmf?<br><br>My OS is Windows 10 and my Python version is 3.9.1.<br></div></div></div><div><br></div><div>Thank you in advance for your help.</div><div><br></div><div>Best regards.</div></div>