コード例 #1
0
        public void TestPauseAudio()
        {
            var engine = new AudioEngine();

            // create a sound effect instance
            SoundEffect soundEffect;

            using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffect = SoundEffect.Load(engine, wavStream);
            var wave1Instance = soundEffect.CreateInstance();

            // create a music instance
            var music = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicFishLampMp3", VirtualFileMode.Open, VirtualFileAccess.Read));

            // check state
            engine.PauseAudio();
            Assert.AreEqual(AudioEngineState.Paused, engine.State);

            // check that existing instance can not be played
            wave1Instance.Play();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            music.Play();
            Assert.AreEqual(SoundPlayState.Stopped, music.PlayState);
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 1000); // listen that nothing comes out

            // create a new sound effect
            SoundEffect soundEffectStereo;

            using (var wavStream = AssetManager.FileProvider.OpenStream("EffectStereo", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffectStereo = SoundEffect.Load(engine, wavStream);

            // check that a new instance can not be played
            soundEffectStereo.Play();
            Assert.AreEqual(SoundPlayState.Stopped, soundEffectStereo.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a stopped sound stay stopped
            engine.ResumeAudio();
            soundEffectStereo.Stop();
            engine.PauseAudio();
            Assert.AreEqual(SoundPlayState.Stopped, soundEffectStereo.PlayState);

            // check that a paused sound stay paused
            engine.ResumeAudio();
            soundEffectStereo.Play();
            soundEffectStereo.Pause();
            engine.PauseAudio();
            Assert.AreEqual(SoundPlayState.Paused, soundEffectStereo.PlayState);

            // check that a playing sound is paused
            engine.ResumeAudio();
            wave1Instance.Play();
            soundEffectStereo.Play();
            music.Play();
            engine.PauseAudio();
            Assert.AreEqual(SoundPlayState.Paused, wave1Instance.PlayState);
            Assert.AreEqual(SoundPlayState.Paused, soundEffectStereo.PlayState);
            Assert.AreEqual(SoundPlayState.Paused, music.PlayState);
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 1000); // listen that nothing comes out

            // check that stopping a sound while paused is possible
            engine.PauseAudio();
            soundEffectStereo.Stop();
            Assert.AreEqual(SoundPlayState.Stopped, soundEffectStereo.PlayState);

            // check that disposing a sound while paused is possible
            engine.PauseAudio();
            music.Dispose();
            Assert.IsTrue(music.IsDisposed);

            soundEffect.Dispose();
            soundEffectStereo.Dispose();
        }
コード例 #2
0
        public void TestResumeAudio()
        {
            var engine = new AudioEngine();

            // create a sound effect instance
            SoundEffect soundEffect;

            using (var wavStream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read))
                soundEffect = SoundEffect.Load(engine, wavStream);
            var wave1Instance = soundEffect.CreateInstance();

            // create a music instance
            var music = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicFishLampMp3", VirtualFileMode.Open, VirtualFileAccess.Read));

            // check that resume do not play stopped instances
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, music.PlayState);
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that user paused music does not resume
            wave1Instance.Play();
            wave1Instance.Pause();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Paused, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that sounds paused by PauseAudio are correctly restarted
            wave1Instance.Play();
            music.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            Assert.AreEqual(SoundPlayState.Playing, music.PlayState);
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 3000); // listen that the sound comes out
            music.Stop();
            TestAudioUtilities.ActiveAudioEngineUpdate(engine, 100);  // stop the music

            // check that a sound stopped during the pause does not play during the resume
            wave1Instance.Play();
            engine.PauseAudio();
            wave1Instance.Stop();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a sound played during the pause do not play during the resume
            engine.PauseAudio();
            wave1Instance.Play();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a two calls to resume do not have side effects (1)
            wave1Instance.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            Utilities.Sleep(2000); // wait that the sound is finished
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a two calls to resume do not have side effects (2)
            wave1Instance.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            wave1Instance.Pause();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Paused, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            // check that a several calls to pause/play do not have side effects
            wave1Instance.Play();
            engine.PauseAudio();
            engine.ResumeAudio();
            engine.PauseAudio();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Playing, wave1Instance.PlayState);
            Utilities.Sleep(2000); // listen that the sound comes out

            // check that the sound is not played if disposed
            wave1Instance.Play();
            engine.PauseAudio();
            wave1Instance.Dispose();
            engine.ResumeAudio();
            Assert.AreEqual(SoundPlayState.Stopped, wave1Instance.PlayState);
            Utilities.Sleep(1000); // listen that nothing comes out

            music.Dispose();
            soundEffect.Dispose();
        }
コード例 #3
0
ファイル: TestSoundMusic.cs プロジェクト: yongweisun/paradox
 private void ActiveAudioEngineUpdate(int miliSeconds)
 {
     TestAudioUtilities.ActiveAudioEngineUpdate(defaultEngine, miliSeconds);
 }