public static bool PlayIfNotPlaying(SoundEffect soundEffect, string soundTypeName) { SoundEffectInstance currentSoundEffectInstance; if (SoundEffectDictionary.TryGetValue(soundTypeName, out currentSoundEffectInstance)) { if (currentSoundEffectInstance.State != SoundState.Playing) { if (currentSoundEffectInstance.IsDisposed) { currentSoundEffectInstance = soundEffect.GetCustomInstance(); } Internal_Play(currentSoundEffectInstance); return(true); } return(false); } else { currentSoundEffectInstance = soundEffect.CreateInstance(); SoundEffectDictionary.Add(soundTypeName, currentSoundEffectInstance); Internal_Play(currentSoundEffectInstance); return(true); } }
private static SoundEffectInstance TryPlay(SoundEffect soundEffect, bool shouldLoop = false, float?volume = null) { var instanceToPlay = soundEffect.GetCustomInstance(); instanceToPlay.IsLooped = shouldLoop; if (instanceToPlay.State != SoundState.Playing && !instanceToPlay.IsDisposed) { Internal_Play(instanceToPlay, volume); } return(instanceToPlay); }