Exemple #1
0
        protected override void Destroy()
        {
            base.Destroy();

            if (IsDisposed)
            {
                return;
            }

            State = AudioEngineState.Disposed;

            SoundBase[] notDisposedSoundsArray;
            lock (notDisposedSounds)
            {
                notDisposedSoundsArray = notDisposedSounds.ToArray();
            }

            // Dispose all the sound not disposed yet.
            foreach (var soundBase in notDisposedSoundsArray)
            {
                soundBase.Dispose();
            }

            --nbOfAudioEngineInstances;

            DestroyImpl();
        }
Exemple #2
0
        /// <summary>
        /// Pause the audio engine. That is, pause all the currently playing <see cref="SoundInstanceBase"/>, and block any future play until <see cref="ResumeAudio"/> is called.
        /// </summary>
        public void PauseAudio()
        {
            if (State != AudioEngineState.Running)
            {
                return;
            }

            State = AudioEngineState.Paused;

            PauseAudioPlatformSpecific();

            pausedSounds.Clear();
            foreach (var sound in notDisposedSounds)
            {
                var soundEffect = sound as SoundEffect;
                if (soundEffect != null)
                {
                    foreach (var instance in soundEffect.Instances)
                    {
                        if (instance.PlayState == SoundPlayState.Playing)
                        {
                            instance.Pause();
                            pausedSounds.Add(instance);
                        }
                    }
                }
                var soundInstance = sound as SoundInstanceBase;
                if (soundInstance != null && soundInstance.PlayState == SoundPlayState.Playing)
                {
                    soundInstance.Pause();
                    pausedSounds.Add(soundInstance);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Resume all audio engine. That is, resume the sounds paused by <see cref="PauseAudio"/>, and re-authorize future calls to play.
        /// </summary>
        public void ResumeAudio()
        {
            if (State != AudioEngineState.Paused)
            {
                return;
            }

            State = AudioEngineState.Running;

            ResumeAudioPlatformSpecific();

            foreach (var playableSound in pausedSounds)
            {
                if (!playableSound.IsDisposed && playableSound.PlayState == SoundPlayState.Paused) // sounds can have been stopped by user while the audio engine was paused.
                {
                    playableSound.Play();
                }
            }
        }
Exemple #4
0
        protected override void Destroy()
        {
            base.Destroy();

            if (IsDisposed)
                return;

            State = AudioEngineState.Disposed;

            SoundBase[] notDisposedSoundsArray;
            lock (notDisposedSounds)
            {
                notDisposedSoundsArray = notDisposedSounds.ToArray();
            }

            // Dispose all the sound not disposed yet.
            foreach (var soundBase in notDisposedSoundsArray)
                soundBase.Dispose();

            --nbOfAudioEngineInstances;

            DestroyImpl();
        }
Exemple #5
0
        /// <summary>
        /// Resume all audio engine. That is, resume the sounds paused by <see cref="PauseAudio"/>, and re-authorize future calls to play.
        /// </summary>
        public void ResumeAudio()
        {
            if(State != AudioEngineState.Paused)
                return;

            State = AudioEngineState.Running;

            ResumeAudioPlatformSpecific();

            foreach (var playableSound in pausedSounds)
            {
                if (!playableSound.IsDisposed && playableSound.PlayState == SoundPlayState.Paused) // sounds can have been stopped by user while the audio engine was paused.
                    playableSound.Play();
            }
        }
Exemple #6
0
        /// <summary>
        /// Pause the audio engine. That is, pause all the currently playing <see cref="SoundInstanceBase"/>, and block any future play until <see cref="ResumeAudio"/> is called.
        /// </summary>
        public void PauseAudio()
        {
            if(State != AudioEngineState.Running)
                return;

            State = AudioEngineState.Paused;

            PauseAudioPlatformSpecific();

            pausedSounds.Clear();
            foreach (var sound in notDisposedSounds)
            {
                var soundEffect = sound as SoundEffect;
                if (soundEffect != null)
                {
                    foreach (var instance in soundEffect.Instances)
                    {
                        if (instance.PlayState == SoundPlayState.Playing)
                        {
                            instance.Pause();
                            pausedSounds.Add(instance);
                        }
                    }
                }
                var soundInstance = sound as SoundInstanceBase;
                if(soundInstance != null && soundInstance.PlayState == SoundPlayState.Playing)
                {
                    soundInstance.Pause();
                    pausedSounds.Add(soundInstance);
                }
            }
        }