when trying to play some sound effects with Qt. This error message is quite misleading. Apart from the obvious circumstance that the audio file is broken, there might be some other causes.
Cause 1: You are trying to play an MP3 file
MP3 files are not supported. You can convert the MP3 file to a WAV file:
ffmpeg -i ding.mp3 ding.wav
Cause 2: You are passing the path, not URL
QSoundEffect.setSource is expecting an URL, not a Path or str. So any one of these works:
View Post on Blog
Qt is a widely adopted GUI framework, but its documentation is quite awful, especially when working in Python. And it's likely that you get the error
when trying to play some sound effects with Qt. This error message is quite misleading. Apart from the obvious circumstance that the audio file is broken, there might be some other causes.
Cause 1: You are trying to play an MP3 file
MP3 files are not supported. You can convert the MP3 file to a WAV file:
Cause 2: You are passing the path, not URL
QSoundEffect.setSource
is expecting an URL, not aPath
orstr
. So any one of these works:But none of these works:
Appendix: Full code