/Multimedia/OpenTK/OpenTKMusic.cs
C# | 147 lines | 97 code | 14 blank | 36 comment | 6 complexity | 976070a57aaa68682563e8b30bb2006b MD5 | raw file
Possible License(s): Apache-2.0
- using System;
- using Delta.Multimedia.BaseOpenAL;
- using Delta.Utilities;
-
- namespace Delta.Multimedia.OpenTK
- {
- /// <summary>
- /// OpenTK music
- /// Sample code for implementing
- /// -> http://www.opentk.com/node/1705
- /// </summary>
- internal class OpenTKMusic : NativeMusic
- {
- #region State (Public)
- /// <summary>
- /// The state of the music, just returning the property of the OggMusicData.
- /// </summary>
- public override MediaState State
- {
- get
- {
- return nativeMusicData.State;
- }
- protected set
- {
- base.State = value;
- }
- }
- #endregion
-
- #region Private
-
- #region nativeMusicData (Private)
- /// <summary>
- /// Music handle
- /// </summary>
- private OggMusicData nativeMusicData;
- #endregion
-
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create OpenTK music
- /// </summary>
- /// <param name="parentMusic">Parent music instance.</param>
- public OpenTKMusic(Music parentMusic)
- : base(parentMusic)
- {
- }
- #endregion
-
- #region LoadNativeData (Public)
- /// <summary>
- /// Load content data
- /// </summary>
- /// <param name="filename">Filename</param>
- /// <returns>True if loading succeeded, otherwise False.</returns>
- public override bool LoadNativeData(string filename)
- {
- try
- {
- nativeMusicData = new OggMusicData(this, filename);
- }
- catch (Exception)
- {
- return false;
- }
-
- return true;
- }
- #endregion
-
- #region Dispose (Public)
- /// <summary>
- /// Dispose data
- /// </summary>
- public override void Dispose()
- {
- if (nativeMusicData != null)
- {
- nativeMusicData.Dispose();
- nativeMusicData = null;
- }
- }
- #endregion
-
- #region Methods (Private)
-
- #region SetVolume
- /// <summary>
- /// Set the volume of the native OpenTK music.
- /// </summary>
- /// <param name="setVolume">Volume to set.</param>
- protected override void SetVolume(float setVolume)
- {
- volume = setVolume;
- nativeMusicData.Volume = volume;
- }
- #endregion
-
- #region PlayNative
- /// <summary>
- /// Play native
- /// </summary>
- protected override void PlayNative()
- {
- try
- {
- nativeMusicData.Play();
- }
- catch (Exception ex)
- {
- Log.Warning("Failed to play OpenTKMusic " + Parent.Name + ": " + ex);
- }
- }
- #endregion
-
- #region UpdateNative
- /// <summary>
- /// Updates the Music
- /// </summary>
- protected override void UpdateNative()
- {
- if (nativeMusicData != null)
- {
- nativeMusicData.Update(ref elapsedPlayTime);
- }
- }
- #endregion
-
- #region StopNative
- /// <summary>
- /// Stop native
- /// </summary>
- protected override void StopNative()
- {
- if (nativeMusicData != null)
- {
- nativeMusicData.Stop();
- }
- }
- #endregion
-
- #endregion
- }
- }