Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
        }