What replaces PyQt5.QtMultimedia / PySide2.QtMultimedia in PyQt6 / PySide6, if anything?

Heads up! You've already completed this tutorial.

PedanticHacker | 2021-03-15 11:40:35 UTC | #1

Hello there! :slight_smile:

I have successfully ported all of my codebase from PyQt5 to PyQt6, thanks to @martin and his blog post. It helped a lot!

I have, however, one area of my codebase that can't be ported to PyQt6. Since Qt6 removed QtMultimedia, PyQt6 / PySide6 as a consequence don't have it anymore.

I was using QtMultimedia's QSound() class to play WAV sound files by using its play() method.

What do you guys propose I use now to play WAV sound files? Is there something similar to QtMultimedia.QSound() in PyQt6 / PySide6? If it is, I can't find it. If not, I need something that is cross-platform (Windows, Linux, Mac) and simple to implement.

Also, do you have any news on whether QtMultimedia is coming back anytime soon, if at all?

Thanks in advance for your answer and stay safe!


PedanticHacker | 2021-03-16 09:02:32 UTC | #2

I forgot to add that I tried to use QtMultimedia from PyQt5 in the event loop of PyQt6, but that doesn't work.


PedanticHacker | 2021-04-07 14:22:13 UTC | #3

After browsing for an answer on the Interwebs, I found out that QtMultimedia is planned to be added back to Qt in version 6.2 (and then, of course, to new versions of PyQt6 / PySide6). So that's good news! Someone on some forum (forgot on which) said that Qt 6.2 is planned to be released around September 2021. We'll just have to wait, I guess.

Anyway, Qt 6.2 (and consequently new versions of PyQt6 / PySide6) is gonna give us these toys: Qt Bluetooth Qt Data Visualization Qt Lottie Animation Qt Multimedia Qt NFC Qt Positioning Qt Quick Dialogs: Folder, Message Box Qt Remote Objects Qt Sensors Qt SerialBus Qt SerialPort Qt WebChannel Qt WebEngine Qt WebSockets * Qt WebView

However, prior to version 6.2, Qt 6.1 will not be so generous and will not be such toy heaven; we'll only get these toys: Active Qt Qt Charts Qt Quick Dialogs (File dialog) Qt ScXML Qt Virtual Keyboard (Meh, okay.*)


PedanticHacker | 2021-03-16 22:57:05 UTC | #4

While we wait for those new toys coming in Qt 6.2 and consequently in new versions of PyQt6 / PySide6, the playsound project found on PyPI is very good. I just tried it and it works as good as QSound() from QtMultimedia.

Install playsound with the pip install playsound command and then import its playsound function in your Python script with from playsound import playsound. It's important that you don't forget to pass the block argument to the playsound function and set it to False; that way the sound will play asynchronously.

python
from playsound import playsound
playsound("path/to/my/sound/file.wav", block=False)

:slight_smile:


martin | 2021-04-07 14:24:23 UTC | #5

Thanks for looking all this up, really appreciate it!

I hit this same snag when trying to migrate over the browser example from the book & had to remove it for the time being. It's a bit of a shame that didn't make it, but a good excuse to refresh the demos a bit.


PedanticHacker | 2021-04-08 10:39:06 UTC | #6

Yeah, too bad QtMultimedia didn't make it to Qt 6.0. But for the time being, I'm using the playsound function from the playsound package.


amohgyebigodwin10691 | 2021-04-09 08:08:26 UTC | #7

If ever playsound is not able to play an audio file, you can use soloman. It plays everything.

python
pip install soloman

and then

python
from soloman import Audio


aud = Audio()
aud.play('/path/to/music.mp3')

PedanticHacker | 2021-04-09 08:29:37 UTC | #8

Yeah, soloman is good, too. But for simple WAV files, playsound is okay. 😉


stelaldridge11281 | 2021-05-28 14:52:22 UTC | #9

I upvote for playsound too, it might be helpful there.


Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt6
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

What replaces PyQt5.QtMultimedia / PySide2.QtMultimedia in PyQt6 / PySide6, if anything? was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.