I am running a QML app using Qt 5.14.2 and notice that my sound effects will not play (generate sound) unless I also have background music playing. I have confirmed with console logging no errors, valid audio file, etc. (11 kbps, 16-bit PCM, 1 channel, wav). I also tried 41kbps sampling rate, no change.
I can reproduce this using Win32 and Android a8. Audio files are asset files (not QRC).
Sample code:
SoundEffect {
id: effect
source : "click.wav"
loops : 1
volume : 0.8
muted : false
}
function play() {
effect.play()
}
The problem with sample code in this type of situation is that a simplistic sample may work. It's possible that playing a 48k stereo file first somehow messes up the audio player - finding a minimally reproducible example is not realistic. So hopefully a general Qt issue is known by someone regarding this topic. I see posts going back to 2017 with similar questions, but no solution.
The wav file should play without dependence on other wav files/sound effects playing.
Something important to note, the sound effect audio file is 0.477 seconds long.
After much trial and error I narrowed this down to a Qt audio player issue. When the audio file is short (eg: 0.5 sec) it sometimes doesn't play as a SoundEffect.
As a solution I appended 1 second of silence to the end of the audio file and now it plays consistently.