How to play a .wav file in QT6?
-
Hi,
I am unable to play a audio file in QT6. I get this error message:
QSoundEffect(qaudio): Error decoding source ./sounds/clock-alarm-beep.wav
when I use code bellow:
import QtQuick import QtQuick.Controls import QtMultimedia ApplicationWindow { visible: true width: 400 height: 600 SoundEffect { id: alarmSound //source: "qrc:/sounds/clock-alarm-beep.wav" source: "./sounds/pager-beeps.wav" //source: "C:/Users/ndias/Desktop/AnalogClock/sounds/clock-alarm-beep.wav" } MouseArea { id: playArea anchors.fill: parent onPressed: { console.info("PLAY"); alarmSound.play(); } } }
I tried to run this sample code on QT5 without any success except when I use the Audio module instead of SoundEffect and using an absolute source URL of the wav file.
Using SoundEffect in QT5 I same error and using Audio module with QRC or relative path source I get no errors but I was unable to play the file.Can anyone give me clarifications on how to overcome this problem?
Best regards
PS: QT6 does not have Audio module
-
Tested with 48kHz sampling rate wav files unsuccessfully (https://www.kozco.com/tech/soundtests.html). I got the same behavior as described in first topic.
-
Hi,
Did you upgrade Qt to 6.2 ?
That said, when using relative paths, did you ensure that the files are stored in the same folder as your application executable ?
-
Hi @SGaist,
I tested it using Qt 6.2 and Qt 5.15.2.
I copied .wav file to same folder application executable file. I forgot this detail before. But I still did not succeed to play wav file.
So this moment I am able only to play wav files using absolute source URL when using Audio module (Qt5).
EDIT: I have no problems when using QRC on Android build (Audio and SoundEffect types) 🙂
-
What if you drop the "./" in the path ?
-
@SGaist said in How to play a .wav file in QT6?:
What if you drop the "./" in the path ?
I get the same result.
Meanwhile I've been testing the compilation on Android with different sample rates. I get the following warning on the console output if audio file does not contain a 48000Hz sample rate. Despite this, .wav file is played.
W AudioTrack: AUDIO_OUTPUT_FLAG_FAST denied by client; transfer 1, track 44100 Hz, output 48000 Hz
Regards
-
On which platform does it fail ?
-
Hi @SGaist
I am using Windows platform.
For Qt5, I tested it with:
- Qt5.15.2 MinGW 32-bit
- Pyside 2
For Qt6, I used:
- qmlscene.exe (6.2.0 MinGW 64-bit) --- Not tested with Qt6.2 MinGW because "QtMultimedia is not currently supported on this platform or compiler"
- Pyside 6.2