PageRenderTime 720ms CodeModel.GetById 120ms app.highlight 4ms RepoModel.GetById 97ms app.codeStats 497ms

/Multimedia/Tests/Program.cs

#
C# | 230 lines | 53 code | 13 blank | 164 comment | 3 complexity | d4d2865c97fab9df1589b5e5fca817db MD5 | raw file
  1using Delta.Engine;
  2using Delta.InputSystem;
  3using Delta.Rendering.Basics.Fonts;
  4using Delta.Utilities;
  5using Delta.Utilities.Datatypes;
  6using Delta.Utilities.Helpers;
  7
  8namespace Delta.Multimedia.Tests
  9{
 10	/// <summary>
 11	/// Multimedia tests, use the Settings.xml to specific which module you want
 12	/// to use (Xna, OpenTK, Vlc, etc.)
 13	/// </summary>
 14	public class Program
 15	{
 16		#region Main (Static)
 17		/// <summary>
 18		/// Main entry point, will just call one of the tests, uncomment the rest
 19		/// </summary>
 20		public static void Main()
 21		{
 22			//TestLoadSound();
 23			//TestLoadSoundWithExtraChunks();
 24			//TestShortSoundPlayback();
 25			//TestManySoundPlaybacks();
 26			//TestManySoundLoads();
 27			//TestDisposeMusicPlayback();
 28			//TestDisposeSoundPlayback();
 29
 30			Tutorials.TestSoundPlayback();
 31			//Tutorials.TestMusicPlayback();
 32			//Tutorials.TestVideoPlayback();
 33		}
 34		#endregion
 35
 36		#region TestLoadSound (Static)
 37		/// <summary>
 38		/// Load a sound file (not playing it)
 39		/// </summary>
 40		public static void TestLoadSound()
 41		{
 42			Sound testSound = new Sound("DefaultSound");
 43			Assert.NotNull(testSound);
 44			Assert.NotNull(testSound);
 45		}
 46		#endregion
 47
 48		/*TODO: content missing! TestDataChunkSound.wav needs to be uploaded (from Marcels folder)
 49		/// <summary>
 50		/// Load a sound file (not playing it) with extra chunks before
 51		/// the actual data chunk. Note: This file is broken on purpose.
 52		/// </summary>
 53		public static void TestLoadSoundWithExtraChunks()
 54		{
 55			Sound testSound = new Sound("TestDataChunkSound");
 56			Assert.NotNull(testSound);
 57			Assert.NotNull(testSound as Sound);
 58		}
 59		 */
 60
 61		#region TestShortSoundPlayback (Static)
 62		/// <summary>
 63		/// Short sound playback as an introduction
 64		/// </summary>
 65		public static void TestShortSoundPlayback()
 66		{
 67			int currentVolume = 10;
 68
 69			Sound sound = new Sound("DefaultSound");
 70			Application.Start(delegate
 71			{
 72				Font.Default.Draw("Volume: " + (currentVolume * 10) + "%",
 73					ScreenSpace.DrawArea);
 74
 75				if (Input.Touch.TouchReleased ||
 76				    Input.Keyboard.SpaceReleased)
 77				{
 78					sound.Play();
 79				}
 80
 81				// Volume Up
 82				if (Input.Keyboard.CursorUpReleased)
 83				{
 84					currentVolume = MathHelper.Min(currentVolume + 1, 10);
 85					sound.Volume = currentVolume / 10.0f;
 86				}
 87
 88				// Volume Down
 89				if (Input.Keyboard.CursorDownReleased)
 90				{
 91					currentVolume = MathHelper.Max(currentVolume - 1, 0);
 92					sound.Volume = currentVolume / 10.0f;
 93				}
 94			});
 95		}
 96		#endregion
 97
 98		/*TODO: The following tests needs extra content!
 99		/// <summary>
100		/// Load multiple sound files
101		/// </summary>
102		public static void TestManySoundLoads()
103		{
104			string[] sounds = new string[]
105			{
106				"AirHockeyWallVariant3",
107				"MenuContinueButtonPressed",
108				"MenuBackButtonPressed",
109			};
110
111			bool loopPlays = false;
112
113			Application.Start(delegate
114			{
115				Font.DrawTopLeftInformation("Fps: " + Time.Fps);
116
117				if (Input.Touch.TouchReleased ||
118					Input.Keyboard.SpaceReleased)
119				{
120					loopPlays = !loopPlays;
121				}
122
123				if (loopPlays)
124				{
125					foreach (string soundName in sounds)
126					{
127						new Sound(soundName).Play();
128					}
129				}
130			});
131		}
132		 */
133
134		/*TODO: The following tests needs extra content!
135		/// <summary>
136		/// Multiple sound playback
137		/// </summary>
138		public static void TestManySoundPlaybacks()
139		{
140			Sound[] sounds = new Sound[]
141			{
142				new Sound("DefaultSound"),
143				new Sound("TimeOver"),
144				new Sound("ResultScreenFirework"),
145				new Sound("TimeLast30SecondsStart"),
146			};
147
148			bool loopPlays = false;
149
150			Delta.Engine.Application.Start(delegate
151			{
152				Application.Window.Title = "ActiveChannels=" +
153					Sound.ActiveChannels;
154
155				if (Input.Touch.TouchReleased ||
156					Input.Keyboard.SpaceReleased)
157				{
158					loopPlays = !loopPlays;
159				}
160
161				if (loopPlays)
162				{
163					foreach (Sound sound in sounds)
164					{
165						sound.Play();
166						System.Threading.Thread.Sleep(20);
167					}
168				}
169
170				if (Sound.ActiveChannels == Application.Information.MaxSoundChannels)
171				{
172					loopPlays = false;
173				}
174			});
175		}
176		 */
177
178		/*TODO: Need to import the Menu music
179		/// <summary>
180		/// Dispose sound file
181		/// </summary>
182		public static void TestDisposeMusicPlayback()
183		{
184			Music music = new Music("Menu");
185
186			Application.Start(delegate
187			{
188				Font.DrawTopLeftInformation("Fps: " + Time.Fps);
189
190				if (Input.Touch.TouchReleased ||
191					Input.Keyboard.SpaceReleased)
192				{
193					//Music is disposed by Media Manager, on load of new one
194					//music.Stop();
195					//music.Dispose();
196					music = new Music("Menu");
197
198					music.Play();
199				}
200			});
201		}
202		 */
203
204		/*TODO: needs AirHockeyWallVariant3 sound content
205		/// <summary>
206		/// Test dispose music playback. Should do nothing for 5 seconds (well,
207		/// except loading and disposing the sound like crazy), then play it!
208		/// </summary>
209		public static void TestDisposeSoundPlayback()
210		{
211			Application.Start(delegate
212			{
213				Font.DrawTopLeftInformation("Fps: " + Time.Fps);
214
215				if (Time.Seconds < 5)
216				{
217					Sound sound = new Sound("AirHockeyWallVariant3");
218					sound.Play();
219					sound.Dispose();
220				}
221				else
222				{
223					Sound sound = new Sound("AirHockeyWallVariant3");
224					sound.Play();
225				}
226			});
227		}
228		 */
229	}
230}