PageRenderTime 39ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Multimedia/Tests/Program.cs

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