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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With