/Multimedia/OpenTK/OpenTKMusic.cs
C# | 147 lines | 97 code | 14 blank | 36 comment | 6 complexity | 976070a57aaa68682563e8b30bb2006b MD5 | raw file
1using System; 2using Delta.Multimedia.BaseOpenAL; 3using Delta.Utilities; 4 5namespace Delta.Multimedia.OpenTK 6{ 7 /// <summary> 8 /// OpenTK music 9 /// Sample code for implementing 10 /// -> http://www.opentk.com/node/1705 11 /// </summary> 12 internal class OpenTKMusic : NativeMusic 13 { 14 #region State (Public) 15 /// <summary> 16 /// The state of the music, just returning the property of the OggMusicData. 17 /// </summary> 18 public override MediaState State 19 { 20 get 21 { 22 return nativeMusicData.State; 23 } 24 protected set 25 { 26 base.State = value; 27 } 28 } 29 #endregion 30 31 #region Private 32 33 #region nativeMusicData (Private) 34 /// <summary> 35 /// Music handle 36 /// </summary> 37 private OggMusicData nativeMusicData; 38 #endregion 39 40 #endregion 41 42 #region Constructors 43 /// <summary> 44 /// Create OpenTK music 45 /// </summary> 46 /// <param name="parentMusic">Parent music instance.</param> 47 public OpenTKMusic(Music parentMusic) 48 : base(parentMusic) 49 { 50 } 51 #endregion 52 53 #region LoadNativeData (Public) 54 /// <summary> 55 /// Load content data 56 /// </summary> 57 /// <param name="filename">Filename</param> 58 /// <returns>True if loading succeeded, otherwise False.</returns> 59 public override bool LoadNativeData(string filename) 60 { 61 try 62 { 63 nativeMusicData = new OggMusicData(this, filename); 64 } 65 catch (Exception) 66 { 67 return false; 68 } 69 70 return true; 71 } 72 #endregion 73 74 #region Dispose (Public) 75 /// <summary> 76 /// Dispose data 77 /// </summary> 78 public override void Dispose() 79 { 80 if (nativeMusicData != null) 81 { 82 nativeMusicData.Dispose(); 83 nativeMusicData = null; 84 } 85 } 86 #endregion 87 88 #region Methods (Private) 89 90 #region SetVolume 91 /// <summary> 92 /// Set the volume of the native OpenTK music. 93 /// </summary> 94 /// <param name="setVolume">Volume to set.</param> 95 protected override void SetVolume(float setVolume) 96 { 97 volume = setVolume; 98 nativeMusicData.Volume = volume; 99 } 100 #endregion 101 102 #region PlayNative 103 /// <summary> 104 /// Play native 105 /// </summary> 106 protected override void PlayNative() 107 { 108 try 109 { 110 nativeMusicData.Play(); 111 } 112 catch (Exception ex) 113 { 114 Log.Warning("Failed to play OpenTKMusic " + Parent.Name + ": " + ex); 115 } 116 } 117 #endregion 118 119 #region UpdateNative 120 /// <summary> 121 /// Updates the Music 122 /// </summary> 123 protected override void UpdateNative() 124 { 125 if (nativeMusicData != null) 126 { 127 nativeMusicData.Update(ref elapsedPlayTime); 128 } 129 } 130 #endregion 131 132 #region StopNative 133 /// <summary> 134 /// Stop native 135 /// </summary> 136 protected override void StopNative() 137 { 138 if (nativeMusicData != null) 139 { 140 nativeMusicData.Stop(); 141 } 142 } 143 #endregion 144 145 #endregion 146 } 147}