Reputation: 119
In my app I'm using SoundEffect to play some sounds. I want to know if there's a way of knowing when a SoundEffect finished its run so a second one will start right after.
Upvotes: 0
Views: 1140
Reputation: 58
the old question, but i had to do the same thing today, i tried the method based on duration but finally stopped with own solution which seems the simplest for me:
1) create static helper class let's say 'SoundsManager' as in lysergic-acid's answer.
2) create a Queue of SoundsEffectInstanses and play first of them ("_sheduledSounds" in code below).
3) Update class with each game loop and check if soundinstance is stopped:
public static void Update()
{
if (_sheduledSounds != null && _sheduledSounds.Count > 1)
{
if (_sheduledSounds.Peek().State == SoundState.Stopped)
{
_sheduledSounds.Dequeue();
_sheduledSounds.Peek().Play();
}
}
}
Upvotes: 1
Reputation: 20050
This scenario is not supported out of the box by XNA as far as i know.
The SoundEffect class exposes a Duration property that you might use to achieve what you're after.
Build some "SoundManager" class (basically a simple scheduler), that will do all the fancy coordination of sounds playback.
This class will hit off a SoundEffect playback, scheduling the next one to occur exactly after Duration had elapsed.
Upvotes: 2
Reputation: 2154
Set this BufferDescription.GlobalFocus flag = True;
This will tell a SoundEffect finished its run.
Upvotes: 0