/Multimedia/Tests/Tutorials.cs
C# | 217 lines | 160 code | 21 blank | 36 comment | 10 complexity | 13f2527b79b995bcffe4e4ae225610e7 MD5 | raw file
Possible License(s): Apache-2.0
- using System;
- using Delta.Engine;
- using Delta.InputSystem;
- using Delta.Rendering.Basics.Fonts;
- using Delta.Utilities;
- using Delta.Utilities.Datatypes;
- using Delta.Utilities.Helpers;
- using NUnit.Framework;
-
- namespace Delta.Multimedia.Tests
- {
- /// <summary>
- /// Multimedia tutorials to perform simple multimedia tasks like playing back
- /// sounds, music or video files and manipulating properties while doing so.
- /// </summary>
- internal class Tutorials
- {
- #region TestSoundPlayback (Static)
- /// <summary>
- /// Tutorial: Multimedia Tutorial 1: Sound Playback
- /// Difficulty: Easy
- /// Description: Plays back the DefaultSound and allows to modify its
- /// volume. Accepts input from mouse, keyboard, game pads and touch.
- /// Image: http://DeltaEngine.net/Icons/Multimedia.png
- /// </summary>
- [Test, Category("Visual")]
- public static void TestSoundPlayback()
- {
- int currentVolume = 10;
-
- Sound testSound = new Sound("DefaultSound");
- Application.Start(delegate
- {
- Application.Window.Title = "ActiveChannels=" + Sound.ActiveChannels;
-
- Font.Default.Draw("Volume: " + (currentVolume * 10) + "%",
- Rectangle.FromCenter(Point.Half, Size.Half));
- Font.Default.Draw(
- "Click, Touch or Press Space or GamePad A to play sound\n" +
- "Use Up/Down to change volume.",
- Rectangle.FromCenter(
- Point.Half + new Point(0, Font.Default.LineHeight * 2),
- Size.Half));
-
- if (Input.Touch.TouchReleased ||
- Input.Mouse.LeftButtonReleased ||
- Input.GamePad.AReleased ||
- Input.Keyboard.SpaceReleased)
- {
- testSound.Volume = currentVolume / 10.0f;
- testSound.Play();
- }
-
- // Volume Up
- if (Input.Keyboard.CursorUpReleased)
- {
- currentVolume = MathHelper.Min(currentVolume + 1, 10);
- }
-
- // Volume Down
- if (Input.Keyboard.CursorDownReleased)
- {
- currentVolume = MathHelper.Max(currentVolume - 1, 0);
- }
- });
- }
- #endregion
-
- #region TestMusicPlayback (Static)
- /// <summary>
- /// Tutorial: Multimedia Tutorial 2: Music Playback
- /// Difficulty: Easy
- /// Description: Plays the DefaultMusic file and allows to change the
- /// volume. Also displays some information about the music file.
- /// Image: http://DeltaEngine.net/Icons/Multimedia.png
- /// </summary>
- [Test, Category("Visual")]
- public static void TestMusicPlayback()
- {
- Music music = new Music("DefaultMusic");
-
- Rectangle stateRect = Rectangle.FromCenter(Point.Half, Size.Half);
- Rectangle volumeRect = Rectangle.FromCenter(
- Point.Half + new Point(0, Font.Default.LineHeight), Size.Half);
- Rectangle timePlayedRect = Rectangle.FromCenter(
- Point.Half + new Point(0, Font.Default.LineHeight * 2), Size.Half);
- float currentVolume = 1.0f;
-
- Application.Start(delegate
- {
- Font.Default.Draw(
- "Music state: " + music.State + " (press Space to start)",
- stateRect);
- Font.Default.Draw(
- "Volume: " + (currentVolume * 100) + "%" +" (use Up/Down to change)",
- volumeRect);
- Font.Default.Draw(
- "Time played: " + music.TimePlayed + " sec (use Enter to pause)",
- timePlayedRect);
-
- #region Play
- if (Input.Touch.TouchReleased ||
- Input.Keyboard.SpaceReleased)
- {
- music.Play();
- }
- #endregion
-
- #region Stop
- if (Input.Keyboard.EnterReleased)
- {
- music.Stop();
- }
- #endregion
-
- #region Volume Up
- if (Input.Keyboard.CursorUpReleased)
- {
- currentVolume = MathHelper.Min(currentVolume + 0.1f, 1.0f);
- music.Volume = currentVolume;
- }
- #endregion
-
- #region Volume Down
- if (Input.Keyboard.CursorDownReleased)
- {
- currentVolume = MathHelper.Max(currentVolume - 0.1f, 0.0f);
- music.Volume = currentVolume;
- }
- #endregion
- });
- }
- #endregion
-
- #region TestVideoPlayback (Static)
- /// <summary>
- /// Tutorial: Multimedia Tutorial 3: Video Playback
- /// Difficulty: Easy
- /// Description: Test Video playback, works on all platforms. The video
- /// format is very different on each platform (.mpg, .wmv, .avi).
- /// Image: http://DeltaEngine.net/Icons/Multimedia.png
- /// </summary>
- [Test, Category("Visual")]
- public static void TestVideoPlayback()
- {
- // Make sure we have a video module setup, otherwise video playback will
- // not work (Vlc is disabled by default on Windows, but should be set for
- // this project).
- Assert.False(String.IsNullOrEmpty(Settings.Modules.VideoModule),
- "This test needs a video module setup in the settings to work!");
-
- Video deltaIntro = Video.Create("DeltaEngineLogo");
- deltaIntro.Ended += delegate
- {
- Log.Info(
- "TestVideoPlayback: Playing intro has ended with state '" +
- deltaIntro.State + "'.", false);
- };
-
- bool isFirstRun = true;
- Application.Start(delegate
- {
- Font.DrawTopLeftInformation("Video state: " + deltaIntro.State);
-
- if ((isFirstRun ||
- Input.Keyboard.SpaceReleased) &&
- deltaIntro.State != MediaState.Playing)
- {
- isFirstRun = false;
-
- Log.Info("TestVideoPlayback: Start playing video", false);
- deltaIntro.Play();
- }
- });
- }
- #endregion
-
- #region TestPlaylistPlayback (Static)
- /// <summary>
- /// Tutorial: Multimedia Tutorial 4: Playlist Playback
- /// Difficulty: Easy
- /// Description: Test Music Playlist playback, works on all platforms.
- /// Image: http://DeltaEngine.net/Icons/Multimedia.png
- /// </summary>
- [Test, Category("Visual")]
- public static void TestPlaylistPlayback()
- {
- MusicPlaylist playlist = new MusicPlaylist();
- playlist.Add(new Music("DefaultMusic"));
- playlist.Add(new Music("DefaultMusic")
- {
- Volume = 0.5f,
- });
- playlist.Add(new Music("DefaultMusic"));
- playlist.Add(new Music("DefaultMusic")
- {
- Volume = 0.5f,
- });
-
- bool isFirstRun = true;
- Application.Start(delegate
- {
- Font.DrawTopLeftInformation(
- "Playlist index: " +
- (playlist.CurrentIndex + 1) + "/" + playlist.Count);
-
- if (isFirstRun ||
- Input.Keyboard.SpaceReleased)
- {
- isFirstRun = false;
- playlist.Play();
- }
- });
- }
- #endregion
- }
- }