Basically, I want to obtain the state of a given instance of SoundEffects in XNA 4.0. Is there a way to know whether a sound is currently playing or stopped?
Asked
Active
Viewed 789 times
1
-
1If there is no built in method you can simply use a boolean check that you created yourself. – Sir Nov 20 '13 at 00:15
-
But with such flag I could only know if the sound was started (played) but not when it has stopped (ended after the duration of the sound)... – ares_games Nov 20 '13 at 00:19
-
1do you know the duration of the sound file too ? simply set the start time and check if time passed is > than the duration of the file. – Sir Nov 20 '13 at 00:21
-
Yes, this should work. Could you add this as an answer? – ares_games Nov 20 '13 at 00:29
-
1Well there might be a built in function that does the job for you so lets wait for other answers. – Sir Nov 20 '13 at 00:31
-
Sure, let's wait. However, there are no build-in functions for that (I checked). – ares_games Nov 20 '13 at 00:33
1 Answers
3
Yes, it's possible, but you need to use SoundEffectInstance
. You can create it using SoundEffect.CreateInstance
method. Remember that the SoundEffectInstance
is created as stopped, initially.
That class has the SoundEffectInstance.State
property that allows you to get the current state of the sound effect: playing, paused, or stopped.
Reference MSDN.

pinckerman
- 4,115
- 6
- 33
- 42