Playing Multiple Sounds at Once in Qt
I'm trying to play background music along with sound effects using Qt. However, I can't get more than one sound to play at once. For example:
QSound::play("Music.wav");
QSound::pl开发者_运维技巧ay("Effect.wav");
When this code is run (on Windows), you can hear Music.wav just start to play, but then it stops and Effect.wav plays. Is there any way to get the two sounds to play at once?
You're using the static method.
Instantiate a QSound object for each:
QSound music("Music.wav");
QSound effect("Effect.wav");
music.play();
effect.play();
This is dependent on the underlying platform audio facilities (see: http://doc.trolltech.com/4.6/qsound.html#details), so if the first playback still stops upon playing the second ... that's why. At that point you would want to look at the QT Phonon module: http://doc.trolltech.com/4.6/phonon-module.html
精彩评论