public static void Update() { for (int i = mSoundEffectPlayInfos.Count - 1; i > -1; i--) { SoundEffectPlayInfo sepi = mSoundEffectPlayInfos[i]; if (TimeManager.SecondsSince(sepi.LastPlayTime + sepi.SoundEffect.Duration.TotalSeconds) > 0) { mSoundEffectPlayInfos.RemoveAt(i); } } // TODO: Execute instructions #if !WINDOWS_PHONE && !MONOGAME && !SILVERLIGHT for (int i = 0; i < PositionedSounds.Count; i++) { PositionedSounds[i].TimedActivity( TimeManager.SecondDifference, TimeManager.SecondDifferenceSquaredDividedByTwo, TimeManager.LastSecondDifference); } #endif // TODO [msmith] Get this working again once we add the data into the asset folder. /* TODO MDS_TEMP #if MONODROID * if ((DateTime.Now - _lastPlay).Milliseconds > 200) * { * if (_droidLoop != null) * { * _droidLoop.Play(0, 0, 0); * _lastPlay = DateTime.Now; * }else * { * _droidLoop = FlatRedBallServices.Load<SoundEffect>(@"performanceloop"); * } * } #endif */ }
/// <summary> /// Plays the argument sound effect. /// </summary> /// <param name="soundEffect">The sound effect to play</param> /// <param name="volume">Volume, ranging from 0.0f (silence) to 1.0f (full volume). 1.0f is full volume</param> /// <param name="pitch">Pitch, ranging from -1.0f (one octave down) to 1.0f (one octave up). 0.0f means no change </param> /// <param name="pan">Volume, ranging from -1.0f (full left) to 1.0f (full right). 0.0f is centered </param> public static void Play(SoundEffect soundEffect, float volume, float pitch = 0, float pan = 0) { #if DEBUG #if !SILVERLIGHT && !MONOGAME if (soundEffect.IsDisposed) { throw new ArgumentException("Argument SoundEffect is disposed"); } #endif #endif if (AreSoundEffectsEnabled) { bool shouldPlay = SoundEffectPlayingBehavior == Audio.SoundEffectPlayingBehavior.PlayAlways || mSoundsPlayedThisFrame.Contains(soundEffect.Name) == false; if (shouldPlay) { #if MONODROID _lastPlay = DateTime.Now; #endif #if ANDROID && !DEBUG try { if (volume < 1 || pitch != 0.0f || pan != 0.0f) { soundEffect.Play(volume, pitch, pan); } else { soundEffect.Play(); } } catch { // Sept 28, 2015 // Monogame 3.4 (and probably 3.5) does not support // playing Sounds on ARM 64 devices. It crashes. We will // catch it in release in case someone releases a FRB game // and doesn't test it on these devices - better to be quiet // than to crash. In debug it will crash like normal (see below) } #else if (volume < 1 || pitch != 0.0f || pan != 0.0f) { soundEffect.Play(volume, pitch, pan); } else { soundEffect.Play(); } #endif #if DEBUG NumberOfSoundEffectPlays++; #endif if (SoundEffectPlayingBehavior == Audio.SoundEffectPlayingBehavior.OncePerFrame) { mSoundsPlayedThisFrame.Add(soundEffect.Name); } SoundEffectPlayInfo sepi = new SoundEffectPlayInfo(); sepi.LastPlayTime = TimeManager.CurrentTime; sepi.SoundEffect = soundEffect; mSoundEffectPlayInfos.Add(sepi); } } }
/// <summary> /// Plays the argument sound effect. /// </summary> /// <param name="soundEffect">The sound effect to play</param> /// <param name="volume">Volume, ranging from 0.0f (silence) to 1.0f (full volume). 1.0f is full volume</param> public static void Play(SoundEffect soundEffect, float volume) { #if DEBUG #if !SILVERLIGHT && !MONOGAME if (soundEffect.IsDisposed) { throw new ArgumentException("Argument SoundEffect is disposed"); } #endif #endif if (AreSoundEffectsEnabled) { bool shouldPlay = SoundEffectPlayingBehavior == Audio.SoundEffectPlayingBehavior.PlayAlways || mSoundsPlayedThisFrame.Contains(soundEffect.Name) == false; if (shouldPlay) { #if MONODROID _lastPlay = DateTime.Now; #endif #if ANDROID && !DEBUG try { if (volume < 1) { soundEffect.Play(volume, 0, 0); } else { soundEffect.Play(); } } catch { // Sept 28, 2015 // Monogame 3.4 (and probably 3.5) does not support // playing Sounds on ARM 64 devices. It crashes. We will // catch it in release in case someone releases a FRB game // and doesn't test it on these devices - better to be quiet // than to crash. In debug it will crash like normal (see below) } #else if (volume < 1) { soundEffect.Play(volume, 0, 0); } else { soundEffect.Play(); } #endif #if DEBUG NumberOfSoundEffectPlays++; #endif if (SoundEffectPlayingBehavior == Audio.SoundEffectPlayingBehavior.OncePerFrame) { mSoundsPlayedThisFrame.Add(soundEffect.Name); } SoundEffectPlayInfo sepi = new SoundEffectPlayInfo(); sepi.LastPlayTime = TimeManager.CurrentTime; sepi.SoundEffect = soundEffect; mSoundEffectPlayInfos.Add(sepi); } } }