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?
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:
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.
from playsound import playsound
playsound("path/to/my/sound/file.wav", block=False)
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.