SoundEffect.Play()
plays the sound effect in a "fire-and-forget" fashion. The sound plays once and its lifetime is managed by the framework. You are not able to change the properties (volume, pan, pitch) of the sound during playback, loop it, position it in 3D or pause it.
You can hold a reference to the playing sound by creating a SoundEffectInstance
. Instead of calling SoundEffect.Play()
, call CreateInstance()
on the SoundEffect
and then Play()
on the new instance:
SoundEffectInstance instance = mySound.CreateInstance();
// Set some properties
instance.Pitch = 1.0f;
instance.IsLooped = true;
// Play the sound effect
instance.Play();
There can be multiple instances of the same SoundEffect
, each with their own properties. The instance can be replayed by calling Play()
after the playback has stopped.