protected override async Task LoadContent() { await base.LoadContent(); music = Asset.Load<SoundMusic>("MusicFishLampMp3"); effect = Asset.Load<SoundEffect>("EffectBip"); music.IsLooped = true; effect.IsLooped = true; music.Play(); effect.Play(); }
public void Initialize() { Game.InitializeAssetDatabase(); defaultEngine = new AudioEngine(); monoInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicBip")); stereoInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicStereo")); contInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicToneA")); mp3Instance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")); wavInstance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicBip")); }
protected override Task LoadContent() { effect48kHz = Asset.Load<SoundEffect>("Effect48000Hz"); effect11kHz = Asset.Load<SoundEffect>("Effect11025Hz"); effect22kHz = Asset.Load<SoundEffect>("Effect22050Hz"); effect11kHzStereo = Asset.Load<SoundEffect>("Effect11025HzStereo"); effect22kHzStereo = Asset.Load<SoundEffect>("Effect22050HzStereo"); effectA = Asset.Load<SoundEffect>("EffectToneA"); musicA = Asset.Load<SoundMusic>("MusicToneA"); return Task.FromResult(true); }
public void Initialize() { Game.InitializeAssetDatabase(); engine = new AudioEngine(); using (var stream = AssetManager.FileProvider.OpenStream("EffectBip", VirtualFileMode.Open, VirtualFileAccess.Read)) { oneSound = SoundEffect.Load(engine, stream); } oneSound.IsLooped = true; sayuriPart = SoundMusic.Load(engine, AssetManager.FileProvider.OpenStream("MusicFishLampMp3", VirtualFileMode.Open, VirtualFileAccess.Read)); sayuriPart.IsLooped = true; }
public void TestVarious() { // test 0 mp3Instance.Play(); mp3Instance.Stop(); mp3Instance.Play(); mp3Instance.Stop(); mp3Instance.Play(); mp3Instance.Stop(); mp3Instance.Play(); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "mp3Instance is not playing (test0)"); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "mp3Instance is not still playing (test0)"); mp3Instance.Stop(); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not stopped (test0)"); //// test 1 monoInstance.Play(); monoInstance.Stop(); monoInstance.Play(); monoInstance.Stop(); monoInstance.Play(); monoInstance.Stop(); monoInstance.Play(); Assert.AreEqual(SoundPlayState.Playing, monoInstance.PlayState, "monoInstance is not playing (test1)"); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not stopped (test1)"); // test 2 mp3Instance.Play(); mp3Instance.Stop(); monoInstance.Play(); monoInstance.Stop(); monoInstance.Play(); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not stopped (test2)"); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not stopped (test2)"); // test 3 monoInstance.Play(); mp3Instance.Play(); monoInstance.Play(); mp3Instance.Play(); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "mp3Instance is not playing (test3)"); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not stopped (test3)"); monoInstance.Play(); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not stopped (test3)"); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not playing (test3)"); // test 4 monoInstance.Play(); mp3Instance.Play(); monoInstance.Play(); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not stopped (test4)"); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not Stopped (test4)"); // test 5 monoInstance.Play(); contInstance.Play(); mp3Instance.Play(); monoInstance.Stop(); contInstance.Stop(); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not stopped (test5)"); Assert.AreEqual(SoundPlayState.Stopped, contInstance.PlayState, "contInstance is not stopped (test5)"); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "mp3Instance is not playing (test5)"); ActiveAudioEngineUpdate(2100); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "mp3Instance is not still playing (test5)"); // test 6: delayed Pause after several play monoInstance.Play(); monoInstance.Pause(); Assert.AreEqual(SoundPlayState.Paused, monoInstance.PlayState, "monoInstance is not Paused 1(test6)"); ActiveAudioEngineUpdate(200); Assert.AreEqual(SoundPlayState.Paused, monoInstance.PlayState, "monoInstance is not Paused 2(test6)"); monoInstance.Stop(); monoInstance.Play(); mp3Instance.Play(); mp3Instance.Pause(); Assert.AreEqual(SoundPlayState.Paused, mp3Instance.PlayState, "mp3Instance is not Paused 1(test6)"); ActiveAudioEngineUpdate(500); Assert.AreEqual(SoundPlayState.Paused, mp3Instance.PlayState, "mp3Instance is not Paused 2(test6)"); monoInstance.Play(); contInstance.Play(); mp3Instance.Play(); mp3Instance.Pause(); Assert.AreEqual(SoundPlayState.Paused, mp3Instance.PlayState, "mp3Instance is not Paused 3(test6)"); ActiveAudioEngineUpdate(500); Assert.AreEqual(SoundPlayState.Paused, mp3Instance.PlayState, "mp3Instance is not Paused 4(test6)"); // test 7 : random tests. var actionsSet = new List<TestSimpleAction> { //() => { Console.WriteLine("monoInstancePlay");monoInstance.Play(); } , //() => {Console.WriteLine("monoInstancePause");monoInstance.Pause(); } , //() => { Console.WriteLine("monoInstanceStop");monoInstance.Stop(); } , //() => { Console.WriteLine("contInstancePlay");contInstance.Play(); } , //() => { Console.WriteLine("contInstancePause");contInstance.Pause(); } , //() => { Console.WriteLine("contInstanceStop");contInstance.Stop(); } , //() => { Console.WriteLine("mp3InstancePlay"); mp3Instance.Play(); } , //() => { Console.WriteLine("mp3InstancePause");mp3Instance.Pause(); } , //() => { Console.WriteLine("mp3InstanceStop"); mp3Instance.Stop(); } , monoInstance.Play, monoInstance.Pause, monoInstance.Stop, contInstance.Play, contInstance.Pause, contInstance.Stop, mp3Instance.Play, mp3Instance.Pause, mp3Instance.Stop }; contInstance.IsLooped = false; const int NbOfRandActions = 50; for (int i = 0; i < 10; i++) { var rand1 = new Random(i); for (int j = 0; j < NbOfRandActions; j++) actionsSet[rand1.Next(actionsSet.Count)].Invoke(); //Console.WriteLine("monoInstancePlay"); monoInstance.Play(); Assert.AreEqual(SoundPlayState.Playing, monoInstance.PlayState, "monoInstance is not Playing 1(test7)"); Assert.AreEqual(SoundPlayState.Stopped, contInstance.PlayState, "contInstance is not Stopped 1(test7)"); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not Stopped 1(test7)"); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not Stopped 2(test7)"); //Console.WriteLine(""); //Console.WriteLine("END OF LOOP {0}", i); //Console.WriteLine(""); var rand2 = new Random(); // random seed for (int j = 0; j < NbOfRandActions; j++) actionsSet[rand2.Next(actionsSet.Count)].Invoke(); //Console.WriteLine("contInstancePlay"); contInstance.Play(); Assert.AreEqual(SoundPlayState.Playing, contInstance.PlayState, "contInstance is not Playing 3(test7)"); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not Stopped 3(test7)"); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not Stopped 3(test7)"); ActiveAudioEngineUpdate(3000); Assert.AreEqual(SoundPlayState.Stopped, contInstance.PlayState, "contInstance is not Stopped 4(test7)"); } contInstance.Stop(); contInstance.IsLooped = true; // test 8 : try to create a lot of instances { var musics = new SoundMusic[1000]; for (int i = 0; i < musics.Length; i++) musics[i] = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")); musics[musics.Length-1].Play(); ActiveAudioEngineUpdate(3000); musics[musics.Length / 2].Play(); ActiveAudioEngineUpdate(3000); foreach (var music in musics) music.Dispose(); } }
public SoundMusicActionRequest(SoundMusic requester, SoundMusicAction request) { Requester = requester; RequestedAction = request; }
public void TestVolume() { float vol = 0; ////////////////////////////////////////////////////////////////////////////////// // 1. Check that get and set Volume for an Disposed instance throw the 'ObjectDisposedException' var dispInst = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectToneA")); dispInst.Dispose(); Assert.Throws <ObjectDisposedException>(() => vol = dispInst.Volume, "SoundMusic.Volume { get } did not throw the 'ObjectDisposedException' when called from a disposed object."); Assert.Throws <ObjectDisposedException>(() => dispInst.Volume = 0, "SoundMusic.Volume { set } did not throw the 'ObjectDisposedException' when called from a disposed object."); /////////////////////////////////////////////////////////// // 2. Check that Volume set/get do not crash on valid sound var volInst = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectBip")); Assert.DoesNotThrow(() => vol = volInst.Volume, "SoundMusic.Volume { get } crashed."); Assert.DoesNotThrow(() => volInst.Volume = 0.5f, "SoundMusic.Volume { set } crashed."); ///////////////////////////////////////////////////// // 3. Check that Volume value is set to 1 by default Assert.AreEqual(1f, vol, "Default volume value is not 1."); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 4. Check that modifying the volume works and is correctly clamped (result => sound should go up and back down) volInst.IsLooped = true; volInst.Play(); var currentVol = -0.3f; var sign = 1f; while (currentVol >= -0.3f) { Assert.DoesNotThrow(() => volInst.Volume = currentVol, "SoundMusic.Volume { set } crashed."); Assert.DoesNotThrow(() => vol = volInst.Volume, "SoundMusic.Volume { get } crashed."); Assert.AreEqual(MathUtil.Clamp(currentVol, 0, 1), vol, "The volume value is not what is supposed to be."); ActiveAudioEngineUpdate(10); if (currentVol > 1.3) { sign = -1; } currentVol += sign * 0.005f; } volInst.Stop(); ActiveAudioEngineUpdate(1000); /////////////////////////////////////////////////////////////////////////////////////////// // 5. Check that modifying the volume on another instance does not affect current instance var volInst2 = SoundMusic.Load(defaultEngine, OpenDataBaseStream("EffectBip")); volInst.Play(); volInst.Volume = 1; ActiveAudioEngineUpdate(1500); volInst2.Volume = 0.2f; ActiveAudioEngineUpdate(1500); volInst.Stop(); ActiveAudioEngineUpdate(1000); ////////////////////////////////////////////////////////////////////////////////// // 6. Check that volume is correctly memorised and updated when changing music volInst2.Volume = 0.2f; volInst.Volume = 1f; volInst2.IsLooped = true; volInst.Play(); ActiveAudioEngineUpdate(1500); volInst2.Play(); ActiveAudioEngineUpdate(1500); volInst.Play(); ActiveAudioEngineUpdate(1500); volInst2.Stop(); /////////////////////////////////////////////////////////////////////////////// // 7. Check that modifying SoundMusic volume does not modify SoundEffectVolume SoundEffect soundEffect; using (var contStream = AssetManager.FileProvider.OpenStream("EffectToneA", VirtualFileMode.Open, VirtualFileAccess.Read)) { soundEffect = SoundEffect.Load(defaultEngine, contStream); } soundEffect.IsLooped = true; soundEffect.Play(); volInst.Play(); currentVol = -0.3f; sign = 1f; while (currentVol >= -0.3f) { volInst.Volume = currentVol; ActiveAudioEngineUpdate(10); if (currentVol > 1.3) { sign = -1; } currentVol += sign * 0.005f; } volInst.Stop(); soundEffect.Stop(); ActiveAudioEngineUpdate(1000); }
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 void TestDispose() { ////////////////////////////////////////////////////////////// // 1. Check the value of the IsDisposed function before Disposal var instance = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")); Assert.IsFalse(instance.IsDisposed, "The soundEffectInstance returned by CreateInstance is already marked as disposed."); ///////////////////////////////////////// // 2. Check that dispose does not crash Assert.DoesNotThrow(instance.Dispose, "SoundEffectInstance.Dispose crashed throwing an exception"); /////////////////////////////////////////////////////////////////// // 3. Check the Disposal status of the instance after Dispose call Assert.IsTrue(instance.IsDisposed, "The soundEffectInstance is not marked as 'Disposed' after call to SoundEffectInstance.Dispose"); ///////////////////////////////////////////////////////// // 4. Check that another call to Dispose does not crash Assert.Throws <InvalidOperationException>(instance.Dispose, "Extra call to SoundEffectInstance.Dispose did not throw invalid operation exception"); ////////////////////////////////////////////////////////////////////////////////// // 5. Check that there is not crash when disposing an instance while it is playing var otherInst = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")); otherInst.Play(); ActiveAudioEngineUpdate(1000); Assert.DoesNotThrow(otherInst.Dispose, "Call to SoundMusic.Dispose after Play crashed throwing an exception"); /////////////////////////////////////////////////////////// // 6. Check that sound is correctly stopped after dispose. ActiveAudioEngineUpdate(2000); /////////////////////////////////////////////////////////////////////////////////////////////////// // 7. Check that there is no crash if sound disposal happen before the sound is ready to be played var otherInst2 = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")); otherInst2.Play(); defaultEngine.Update(); defaultEngine.Update(); Assert.DoesNotThrow(otherInst2.Dispose, "Call to SoundMusic.Dispose after Play and before ready-to-play state crashed throwing an exception"); ActiveAudioEngineUpdate(1000); //////////////////////////////////////////////////////////////////////////////////// // 8. Check that there is no crash if sound disposal happen before real call to Play var otherInst3 = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")); otherInst3.Play(); otherInst3.Dispose(); Assert.DoesNotThrow(() => ActiveAudioEngineUpdate(1000), "Call to Engine.Update after commited Play/Dispose calls crashed throwing an exception"); ///////////////////////////////////////////////////////////////////////////////////// // 9. Check that there is no crash if sound disposal happen before real call to Stop var otherInst4 = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")); otherInst4.Play(); ActiveAudioEngineUpdate(1000); otherInst4.Stop(); otherInst4.Dispose(); Assert.DoesNotThrow(() => ActiveAudioEngineUpdate(1000), "Call to Engine.Update after commited Stop/Dispose calls crashed throwing an exception"); ///////////////////////////////////////////////////////////////////////////////////// // 10. Check that there is no crash if sound disposal happen before real call to Stop var otherInst5 = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")); otherInst5.Play(); ActiveAudioEngineUpdate(1000); otherInst5.Pause(); otherInst5.Dispose(); Assert.DoesNotThrow(() => ActiveAudioEngineUpdate(1000), "Call to Engine.Update after commited Pause/Dispose calls crashed throwing an exception"); ///////////////////////////////////////////////////////////////////////////////////// // 11. Check that there is no crash if sound disposal happen before real call to Stop var otherInst6 = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")); otherInst6.Play(); ActiveAudioEngineUpdate(1000); otherInst6.Volume = 0.2f; otherInst6.Dispose(); Assert.DoesNotThrow(() => ActiveAudioEngineUpdate(1000), "Call to Engine.Update after commited Volume/Dispose calls crashed throwing an exception"); }
public void TestVarious() { // test 0 mp3Instance.Play(); mp3Instance.Stop(); mp3Instance.Play(); mp3Instance.Stop(); mp3Instance.Play(); mp3Instance.Stop(); mp3Instance.Play(); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "mp3Instance is not playing (test0)"); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "mp3Instance is not still playing (test0)"); mp3Instance.Stop(); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not stopped (test0)"); //// test 1 monoInstance.Play(); monoInstance.Stop(); monoInstance.Play(); monoInstance.Stop(); monoInstance.Play(); monoInstance.Stop(); monoInstance.Play(); Assert.AreEqual(SoundPlayState.Playing, monoInstance.PlayState, "monoInstance is not playing (test1)"); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not stopped (test1)"); // test 2 mp3Instance.Play(); mp3Instance.Stop(); monoInstance.Play(); monoInstance.Stop(); monoInstance.Play(); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not stopped (test2)"); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not stopped (test2)"); // test 3 monoInstance.Play(); mp3Instance.Play(); monoInstance.Play(); mp3Instance.Play(); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "mp3Instance is not playing (test3)"); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not stopped (test3)"); monoInstance.Play(); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not stopped (test3)"); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not playing (test3)"); // test 4 monoInstance.Play(); mp3Instance.Play(); monoInstance.Play(); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not stopped (test4)"); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not Stopped (test4)"); // test 5 monoInstance.Play(); contInstance.Play(); mp3Instance.Play(); monoInstance.Stop(); contInstance.Stop(); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not stopped (test5)"); Assert.AreEqual(SoundPlayState.Stopped, contInstance.PlayState, "contInstance is not stopped (test5)"); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "mp3Instance is not playing (test5)"); ActiveAudioEngineUpdate(2100); Assert.AreEqual(SoundPlayState.Playing, mp3Instance.PlayState, "mp3Instance is not still playing (test5)"); // test 6: delayed Pause after several play monoInstance.Play(); monoInstance.Pause(); Assert.AreEqual(SoundPlayState.Paused, monoInstance.PlayState, "monoInstance is not Paused 1(test6)"); ActiveAudioEngineUpdate(200); Assert.AreEqual(SoundPlayState.Paused, monoInstance.PlayState, "monoInstance is not Paused 2(test6)"); monoInstance.Stop(); monoInstance.Play(); mp3Instance.Play(); mp3Instance.Pause(); Assert.AreEqual(SoundPlayState.Paused, mp3Instance.PlayState, "mp3Instance is not Paused 1(test6)"); ActiveAudioEngineUpdate(500); Assert.AreEqual(SoundPlayState.Paused, mp3Instance.PlayState, "mp3Instance is not Paused 2(test6)"); monoInstance.Play(); contInstance.Play(); mp3Instance.Play(); mp3Instance.Pause(); Assert.AreEqual(SoundPlayState.Paused, mp3Instance.PlayState, "mp3Instance is not Paused 3(test6)"); ActiveAudioEngineUpdate(500); Assert.AreEqual(SoundPlayState.Paused, mp3Instance.PlayState, "mp3Instance is not Paused 4(test6)"); // test 7 : random tests. var actionsSet = new List <TestSimpleAction> { //() => { Console.WriteLine("monoInstancePlay");monoInstance.Play(); } , //() => {Console.WriteLine("monoInstancePause");monoInstance.Pause(); } , //() => { Console.WriteLine("monoInstanceStop");monoInstance.Stop(); } , //() => { Console.WriteLine("contInstancePlay");contInstance.Play(); } , //() => { Console.WriteLine("contInstancePause");contInstance.Pause(); } , //() => { Console.WriteLine("contInstanceStop");contInstance.Stop(); } , //() => { Console.WriteLine("mp3InstancePlay"); mp3Instance.Play(); } , //() => { Console.WriteLine("mp3InstancePause");mp3Instance.Pause(); } , //() => { Console.WriteLine("mp3InstanceStop"); mp3Instance.Stop(); } , monoInstance.Play, monoInstance.Pause, monoInstance.Stop, contInstance.Play, contInstance.Pause, contInstance.Stop, mp3Instance.Play, mp3Instance.Pause, mp3Instance.Stop }; contInstance.IsLooped = false; const int NbOfRandActions = 50; for (int i = 0; i < 10; i++) { var rand1 = new Random(i); for (int j = 0; j < NbOfRandActions; j++) { actionsSet[rand1.Next(actionsSet.Count)].Invoke(); } //Console.WriteLine("monoInstancePlay"); monoInstance.Play(); Assert.AreEqual(SoundPlayState.Playing, monoInstance.PlayState, "monoInstance is not Playing 1(test7)"); Assert.AreEqual(SoundPlayState.Stopped, contInstance.PlayState, "contInstance is not Stopped 1(test7)"); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not Stopped 1(test7)"); ActiveAudioEngineUpdate(2500); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not Stopped 2(test7)"); //Console.WriteLine(""); //Console.WriteLine("END OF LOOP {0}", i); //Console.WriteLine(""); var rand2 = new Random(); // random seed for (int j = 0; j < NbOfRandActions; j++) { actionsSet[rand2.Next(actionsSet.Count)].Invoke(); } //Console.WriteLine("contInstancePlay"); contInstance.Play(); Assert.AreEqual(SoundPlayState.Playing, contInstance.PlayState, "contInstance is not Playing 3(test7)"); Assert.AreEqual(SoundPlayState.Stopped, monoInstance.PlayState, "monoInstance is not Stopped 3(test7)"); Assert.AreEqual(SoundPlayState.Stopped, mp3Instance.PlayState, "mp3Instance is not Stopped 3(test7)"); ActiveAudioEngineUpdate(3000); Assert.AreEqual(SoundPlayState.Stopped, contInstance.PlayState, "contInstance is not Stopped 4(test7)"); } contInstance.Stop(); contInstance.IsLooped = true; // test 8 : try to create a lot of instances { var musics = new SoundMusic[1000]; for (int i = 0; i < musics.Length; i++) { musics[i] = SoundMusic.Load(defaultEngine, OpenDataBaseStream("MusicFishLampMp3")); } musics[musics.Length - 1].Play(); ActiveAudioEngineUpdate(3000); musics[musics.Length / 2].Play(); ActiveAudioEngineUpdate(3000); foreach (var music in musics) { music.Dispose(); } } }
public void PlayMusic() { SoundMusic.PlayMusic(clips); }
public SoundMusicActionRequest(SoundMusic requester, SoundMusicAction request) { Requester = requester; RequestedAction = request; }
public void PlayUsingHandler() { AudioClip c = clips[Random.Range(0, clips.Length)]; SoundMusic.PlaySound(c); }