PDA

View Full Version : play sound repeatedly



ardisaz
4th December 2010, 02:58
Hi guys, i have a little problem using sound at Qt
im creating music player with qt

right now, i'm using phonon each time i want to play the sound, for example:

void drumplayer::play_snare()
{
snare = Phonon::CreatePlayer(Phonon::MusicCategory, Phonon::MediaSource(path));
snare->play();
}

with that code, every time i play the snare of the drum, there will be new object created (and will use the memory a lot for each play).

i have tried to make the initiation of snare separated like this:

void drumplayer::init_snare()
{
snare = Phonon::CreatePlayer(Phonon::MusicCategory, Phonon::MediaSource(path));
}
void drumplayer::play_snare()
{
snare->play();
}

but i cant play the snare repeatedly. If i wan't to play the snare again, i have to put snare->stop(); before i can play again. I also try QSound, but QSound can't play multiple sound

Is there another way to play multiple sound repeatedly?
thx a lot for your help

BalaQT
4th December 2010, 04:54
hi,
did u try
QSound void setLoops ( int l ) ;

hope it helps
Bala

ComaWhite
4th December 2010, 08:27
Have you tried MediaObject::setCurrentSource where it will change the source of the file you want to execute rather than keep creating it like you are doing which is wrong. Then just call play when you need it.

ardisaz
4th December 2010, 09:54
@Bala, thank for your suggestion. But QSound doesn't support multiple sound. Each time i touch another label, the other sound is off

@comaWhite, yes i already try that. But that technique won't let my program use multiple sound.

thx for your suggestion...

Lykurg
4th December 2010, 11:10
what do you mean with multiple? Do you mean you want to play two ore more files at the same moment? If so, you have to construct two or more players. If you play them in a sequence see the queue functions.