开发者

Playing Multiple Sounds at Once in Qt

开发者 https://www.devze.com 2022-12-26 20:31 出处:网络
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:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号