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?
Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.
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.
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.
pip install soloman
and then
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.
PyQt6 Crash Course — a new tutorial in your Inbox every day
Beginner-focused crash course explaining the basics with hands-on examples.