Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Audio looping with XNA on Windows Phone 8 while the sound is still playing

I need a way to start/stop a loop while the sound is still playing. I've found that the best way to play multiple sounds together is to use XNA. So I've created a SoundEffectInstance starting from my SoundEffect object who contains the audio clip. Now the problem is that I have a button which should change the state of this clip from "looped" to "non looping" and viceversa.

Here's the problem: it throws an exception sayning that the loop must be set before the first play. So I thought that, while switching from "non looping" to "looped", I could just wait for the sound to stop and then recreate the SoundEngineInstance, setting IsLooped = true and make it start again. This one works, but there's some delay and this makes you lose your timing, so it's quite useless.

What I'm looking for is a way to set or unset the loop while playing the sound and without any kind of delay.

EDIT:

I tried using two SoundEngineInstance, one looped and one not, and simply switch between them using the volume. The problem is that the non looped one just stops after the first play, so if I loop it for two times and then I put it to non loop status, no sound is played because the non looped clip already ended!

Suggestions?

like image 363
StepTNT Avatar asked Jan 15 '13 19:01

StepTNT


Video Answer


1 Answers

I had the same proplem and I used two instances with the same audio clip to solve it, one with looping and one without it. I switched betwwen the two. It is maybe not the best solution but it worked for me.

like image 163
Ferenc Kun Avatar answered Nov 15 '22 17:11

Ferenc Kun