public void TestIsLooped() { var looped = false; ////////////////////////////////////////////////////////////////////////////////// // 1. Check that get and set IsLooped for an Disposed instance throw the 'ObjectDisposedException' var dispInst = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectToneA")); dispInst.Dispose(); Assert.Throws <ObjectDisposedException>(() => looped = dispInst.IsLooped, "SoundMusic.IsLooped { get } did not throw the 'ObjectDisposedException' when called from a disposed object."); Assert.Throws <ObjectDisposedException>(() => dispInst.IsLooped = false, "SoundMusic.IsLooped { set } did not throw the 'ObjectDisposedException' when called from a disposed object."); ////////////////////////////////////////////////////////////////////////////////// // 2. Check that set IsLooped for a playing instance throw the 'InvalidOperationException' var loopedWavInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectBip")); loopedWavInstance.Play(); Assert.Throws <InvalidOperationException>(() => loopedWavInstance.IsLooped = true, "SoundMusic.IsLooped { set } did not throw the 'InvalidOperationException' when called from a playing sound."); ActiveAudioEngineUpdate(2000); ///////////////////////////////////////////////// // 3. Check that IsLooped default value is false Assert.IsFalse(loopedWavInstance.IsLooped, "Default looping status is not false."); ///////////////////////////////////////////////////////////// // 4. Check that IsLooped set/get do not crash on valid sound Assert.DoesNotThrow(() => looped = loopedWavInstance.IsLooped, "SoundMusic.IsLooped { get } crashed."); Assert.DoesNotThrow(() => loopedWavInstance.IsLooped = true, "SoundMusic.IsLooped { set } crashed."); ////////////////////////////////////////////////////////////// // 5. Check that sound is looping when IsLooped is set to true loopedWavInstance.IsLooped = true; loopedWavInstance.Play(); ActiveAudioEngineUpdate(3000); Assert.AreEqual(SoundPlayState.Playing, loopedWavInstance.PlayState, "Sound does not loop when Islooped is set to true."); loopedWavInstance.Stop(); ActiveAudioEngineUpdate(2000); ////////////////////////////////////////////////////////////// // 6. Check that sound is looping when IsLooped is set to true var loopedMP3Instance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicBipMp3")); loopedMP3Instance.IsLooped = true; loopedMP3Instance.Play(); ActiveAudioEngineUpdate(3000); Assert.AreEqual(SoundPlayState.Playing, loopedMP3Instance.PlayState, "Sound does not loop when Islooped is set to true."); loopedMP3Instance.Stop(); ActiveAudioEngineUpdate(2000); //////////////////////////////////////////////////////////////////////// // 7. Check that sound has no glitches when looped a continuous sound contInstance.IsLooped = true; contInstance.Play(); ActiveAudioEngineUpdate(3000); Assert.AreEqual(SoundPlayState.Playing, contInstance.PlayState, "Sound does not loop when Islooped is set to true."); contInstance.Stop(); }
public void TestPause() { ////////////////////////////////////////////////////////////////////////////////// // 1. Check that pausing an Disposed instance throw the 'ObjectDisposedException' var dispInst = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectToneA")); dispInst.Dispose(); Assert.Throws <ObjectDisposedException>(dispInst.Pause, "SoundMusic.Pause did not throw the 'ObjectDisposedException' when called from a disposed object."); ////////////////////////////////////////////////////////////////////////// // 2. Check that Pause does not crash when the sound is not started/stopped Assert.DoesNotThrow(monoInstance.Pause, "Call to SoundMusic.Pause crashed throwing an exception with a stopped sound."); ////////////////////////////////////////////////////////////////////////////////////////// // 3. Check that Pause does not crash and has the correct effect when called after playing mp3Instance.Play(); ActiveAudioEngineUpdate(2000); Assert.DoesNotThrow(mp3Instance.Pause, "Call to SoundMusic.Pause crashed throwing an exception."); ActiveAudioEngineUpdate(500); mp3Instance.Play(); ActiveAudioEngineUpdate(2000); //////////////////////////////////////////////////////////////////// // 4. Check that a second call to Pause while playing does not crash mp3Instance.Play(); mp3Instance.Pause(); Assert.DoesNotThrow(mp3Instance.Pause, "Second call to SoundMusic.Pause while paused crashed throwing an exception."); /////////////////////////////////////////////////////////////// // 5. Check that Pause from another instance has no influence mp3Instance.Play(); monoInstance.Pause(); ActiveAudioEngineUpdate(1000); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "Pause from another music instance stopped current music."); mp3Instance.Stop(); ActiveAudioEngineUpdate(1000); }
protected override void Update(GameTime gameTime) { base.Update(gameTime); foreach (var pointerEvent in Input.PointerEvents) { if (pointerEvent.State == PointerState.Up) { music.Stop(); music.Play(); //effect.Stop(); //effect.Play(); } } }
public void TestInvalidationDuringSoundMusicPlay() { sayuriPart.Play(); // user should unplug and plug back the the headphone here // and check that sound restart without throwing any exceptions. var count = 0; while (count < 1500) { ++count; Assert.DoesNotThrow(() => sayuriPart.Pause()); engine.Update(); Assert.DoesNotThrow(() => sayuriPart.Play()); engine.Update(); Utilities.Sleep(10); } sayuriPart.Stop(); }
public void SetState(UIState state) { UIState prev = State; State = state; if (State == UIState.MainMenu) { inputRegions.Clear(); inputRegions.Add(new InputRegion(HARDBOILED_INPUTBOX, true, (i) => { if (!Main.HasWon) { return; } if (Rand.Next(RARE_SCREEN_RARITY) == 0) { SetStateNextFrame(UIState.RareStartup); } else { SetStateNextFrame(UIState.Survive); } Main.Level.IsHardBoiled = true; })); inputRegions.Add(new InputRegion(STARTGAME_INPUTBOX, true, (i) => { if (Rand.Next(RARE_SCREEN_RARITY) == 0) { SetStateNextFrame(UIState.RareStartup); } else { SetStateNextFrame(UIState.Survive); } Main.Level.IsHardBoiled = false; })); inputRegions.Add(new InputRegion(FULLSCREEN_INPUTBOX, true, (i) => { Main.MainGame.ToggleFullscreen(); })); InputRegion volumeInput = new InputRegion(VOLUME_INPUTBOX); volumeInput.MouseDown += _volume_MouseDown; inputRegions.Add(volumeInput); menuMusic.Play(); } else { menuMusic.Stop(); } if (State == UIState.RareStartup) { inputRegions.Clear(); RareStartupIndex = Rand.Next(0, RARE_SCREEN_COUNT) + 1; timer = new HelperTimer(TimeSpan.FromSeconds(RARE_STARTUP_TIME), "RareStartupEnd", () => { SetStateNextFrame(UIState.Survive); }); } if (State == UIState.Survive) { inputRegions.Clear(); _staticScreensLeft = STATIC_SCREEN_LENGTH; timer = new HelperTimer(TimeSpan.FromSeconds(SURVIVE_DELAY), "SurviveDelay", () => { timer = new HelperTimer(TimeSpan.FromSeconds(SURVIVE_FADETIME), "SurviveFade", () => { SetStateNextFrame(UIState.Office); }); }); Main.Level.Laptop.soundCameraChange.Play(); } if (State == UIState.YouDied) { inputRegions.Clear(); inputRegions.Add(new InputRegion(Vector2.Zero, WindowSize, true, (i) => { SetStateNextFrame(UIState.MainMenu); })); } if (State == UIState.Static) { inputRegions.Clear(); timer = new HelperTimer(TimeSpan.FromSeconds(DEATH_STATIC_TIME), "DeathStaticEnd", () => { SetState(UIState.YouDied); }); soundStatic.Play(); Main.Level.Office.musicClassicalish.Stop(); } else { soundStatic.Stop(); } if (State == UIState.SixAM) { inputRegions.Clear(); _spamOffset = SPAM_SIZE.Y; timer = new HelperTimer(TimeSpan.FromSeconds(SPAM_DELAY), "SpamBegin", () => { _doingSpam = true; timer = new HelperTimer(TimeSpan.FromSeconds(SPAM_TIME), "SpamEnd", () => { _doingSpam = false; if (Main.Level.IsHardBoiled) { SetState(UIState.Newspaper); } else { SetState(UIState.TheEggnd); } }); }); Main.Level.Office.musicClassicalish.Stop(); } if (State == UIState.TheEggnd) { inputRegions.Clear(); timer = new HelperTimer(TimeSpan.FromSeconds(THE_EGGND_TIME), "TheEggndTime", () => { SetState(UIState.MainMenu); }); Main.Level.spamMusic.Stop(); theEggndMusic.Play(); } else { theEggndMusic.Stop(); } if (State == UIState.Newspaper) { inputRegions.Clear(); timer = new HelperTimer(TimeSpan.FromSeconds(NEWSPAPER_FADEIN_TIME), "NewspaperIn", () => { inputRegions.Add(new InputRegion(Vector2.Zero, WindowSize, true, (n) => { timer = new HelperTimer(TimeSpan.FromSeconds(NEWSPAPER_FADEOUT_TIME), "NewspaperOut", () => { SetStateNextFrame(UIState.MainMenu); newspaperMusic.Stop(); }); })); }); newspaperMusic.Play(); } if (State == UIState.Office) { inputRegions.Clear(); if (prev != UIState.Laptop) { Main.Level.Reset(); } else { Main.Level.Laptop.Hide(); Main.Level.Office.Show(); } } else { Main.Level.Hide(); } if (State == UIState.Laptop) { inputRegions.Clear(); if (prev != UIState.Office) { Main.Level.Reset(); // should never happen } else { Main.Level.Office.Hide(); Main.Level.Laptop.Show(); } } }
public void TestPlay() { ///////////////////////////////////// // 1. Check that Play does not crash Assert.DoesNotThrow(monoInstance.Play, "Call to SoundMusic.Play crashed throwing an exception."); //////////////////////////////////////////////////////////////////// // 2. Check that a second call to Play while playing does not crash Assert.DoesNotThrow(monoInstance.Play, "Second call to SoundMusic.Play while playing crashed throwing an exception."); //////////////////////////////////////////// // 3. Listen that the played sound is valid ActiveAudioEngineUpdate(1500); ////////////////////////////////////////////////////////////////// // 4. Check that there is no crash when restarting the sound Assert.DoesNotThrow(monoInstance.Play, "Restarting the audio sound after it finishes crashed throwing an exception."); ActiveAudioEngineUpdate(200); ////////////////////////////////////////////////////////////////////////////////////////////////////// // 5. Check that there is no crash when playing after pausing the sound and that play flow is correct monoInstance.Pause(); ActiveAudioEngineUpdate(200); Assert.DoesNotThrow(monoInstance.Play, "Restarting the audio sound after pausing it crashed throwing an exception."); ActiveAudioEngineUpdate(1500); ////////////////////////////////////////////////////////////////////////////////////////////////////// // 6. Check that there is no crash when playing after stopping a sound and that the play flow restart monoInstance.Play(); ActiveAudioEngineUpdate(200); monoInstance.Stop(); ActiveAudioEngineUpdate(200); Assert.DoesNotThrow(monoInstance.Play, "Restarting the audio sound after stopping it crashed throwing an exception."); int timeCount = 0; while (monoInstance.PlayState == SoundPlayState.Playing) { ActiveAudioEngineUpdate(1000); timeCount += 1000; if (timeCount > 3000) { Assert.Fail("SoundMusic.Play has not finished after 3 seconds."); } } //////////////////////////////////////////////////////////////// // 7. Play a stereo file a listen that the played sound is valid stereoInstance.Play(); ActiveAudioEngineUpdate(3000); ////////////////////////////////////////////////////////////////////////////////// // 8. Check that Playing an Disposed instance throw the 'ObjectDisposedException' var dispInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectToneA")); dispInstance.Dispose(); Assert.Throws <ObjectDisposedException>(dispInstance.Play, "SoundEffectInstance.Play did not throw the 'ObjectDisposedException' when called from a disposed object."); //////////////////////////////////////////////////////////////// // 9. Play a mp3 file and listen that the played sound is valid mp3Instance.Play(); ActiveAudioEngineUpdate(4000); ////////////////////////////////////////////////////////////////////////////// // 10. Play another music and check that the previous one is correctly stopped monoInstance.Play(); Assert.AreEqual(SoundPlayState.Playing, monoInstance.PlayState, "Mono intstance play status is not what it is supposed to be."); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "MP3 intstance play status is not what it is supposed to be."); ActiveAudioEngineUpdate(1500); }
public Office(Level level) { Level = level; CameraOffset = new Vector2(MAX_CAMERA_OFFSET / 2.0f, 0); lightswitchInput = new InputRegion(LIGHTSWITCH_INPUTBOX, false, (i) => { IsLightOn = !IsLightOn; if (IsLightOn) { soundLightOn.Play(); if (!Level.IsHardBoiled) { musicClassicalish.Play(); } } else { soundLightOff.Play(); Level.Monsters.GoldenFlumpty.Shoo(); if (!Level.IsHardBoiled) // Don't pause music in hard boiled mode { musicClassicalish.Pause(); } } }); buttonLeftInput = new InputRegion(BUTTON_LEFT_OFFSET + CameraOffset, BUTTON_SIZE, true, (i) => { if (Vent != VentState.Left) { Vent = VentState.Left; _ventMoving = true; soundVent.Stop(); soundVent.Play(); } }); buttonRightInput = new InputRegion(BUTTON_RIGHT_OFFSET + CameraOffset, BUTTON_SIZE, false, (i) => { if (Vent != VentState.Right) { Vent = VentState.Right; _ventMoving = true; soundVent.Stop(); soundVent.Play(); } }); rawrInput = new InputRegion(RAWR_HITBOX_OFFSET + CameraOffset, RAWR_HITBOX_SIZE, true, (i) => { soundRawr.Stop(); soundRawr.Play(); // spammable }); muteIntroInput = new InputRegion(MUTE_INTRO_INPUTBOX, false, (i) => { musicIntro.Stop(); showMuteButton = false; muteButtonTimer.Stop(); if (Level.IsHardBoiled) { musicToreador.Play(); } else { musicClassicalish.Play(); } }); Vent = VentState.Left; }