[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    QMediaplayer incorrect duration : how to switch mediaservice backend ?
From:       MisterKartofel <teanh1kns () gmail ! com>
Date:       2021-02-03 10:35:58
Message-ID: CAA4XyY=SqkPApGrrN+cjXQNE8h36vUFDJ0KCsceO4EraeTmaVQ () mail ! gmail ! com
[Download RAW message or body]

Hello,

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
https://forum.learnpyqt.com/t/is-it-just-me-or-is-qmediaplayer-not-working-properly/401
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:

```
import os
os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = 'windowsmediafoundation'
```

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 :

```
import os
# os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = 'windowsmediafoundation'
I also tried to run it here

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtMultimedia import *
import sys

# os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] = 'windowsmediafoundation'
I also tried to run it here

class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)

        self.player = QMediaPlayer()
        self.player.durationChanged.connect(self.print_duration)

self.player.setMedia(QMediaContent(QUrl.fromLocalFile(path_to_file)))
        self.show()

    def print_duration(self, duration):
        print(duration)

if __name__ == "__main__":

    os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] =
'windowsmediafoundation' #This is where I tried to run it first

    app = QApplication(sys.argv)

    # os.environ['QT_MULTIMEDIA_PREFERRED_PLUGINS'] =
'windowsmediafoundation' I also tried to run it here

    window = MainWindow()
    app.exec_()
```

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.

It could be that I'm not using QT_MULTIMEDIA_PREFERRED_PLUGINS correctly,
how can I switch the mediaservice to wmf?

My OS is Windows 10 and my Python version is 3.9.1.

Thank you in advance for your help.

Best regards.

[Attachment #3 (text/html)]

<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 &quot;unusual&quot; 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-pr \
operly/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[&#39;QT_MULTIMEDIA_PREFERRED_PLUGINS&#39;] = \
&#39;windowsmediafoundation&#39;</div><div>```     </div><div><br>The problem is that \
I just can&#39;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[&#39;QT_MULTIMEDIA_PREFERRED_PLUGINS&#39;] = \
&#39;windowsmediafoundation&#39; 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[&#39;QT_MULTIMEDIA_PREFERRED_PLUGINS&#39;] \
= &#39;windowsmediafoundation&#39; 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__ == &quot;__main__&quot;:<br><br>      \
os.environ[&#39;QT_MULTIMEDIA_PREFERRED_PLUGINS&#39;] = \
&#39;windowsmediafoundation&#39; #This is where I tried to run it first<br><br>      \
app = QApplication(sys.argv)<br><br>      # \
os.environ[&#39;QT_MULTIMEDIA_PREFERRED_PLUGINS&#39;] = \
&#39;windowsmediafoundation&#39; 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&#39;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>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic