Audio.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using QuartzTypeLib;
  2. using System;
  3. using System.Windows.Forms;
  4. namespace LYFZ.Software.MainBusiness.CallerWizard
  5. {
  6. public class Audio : Form
  7. {
  8. private const int WM_APP = 32768;
  9. private const int WM_GRAPHNOTIFY = 32769;
  10. private const int EC_COMPLETE = 1;
  11. private int mediaStatus;
  12. private double mediaDuration;
  13. private double mediaCurPos;
  14. private int mediaVolum;
  15. private FilgraphManager objMedia;
  16. private IBasicAudio volMedia;
  17. private IMediaControl ctlMedia;
  18. private IMediaPosition posMedia;
  19. private IMediaEventEx eexMedia;
  20. public int MediaStatus
  21. {
  22. get
  23. {
  24. return this.mediaStatus;
  25. }
  26. }
  27. public int MediaDuration
  28. {
  29. get
  30. {
  31. return (int)this.mediaDuration;
  32. }
  33. }
  34. public int MediaCurPos
  35. {
  36. get
  37. {
  38. if (this.posMedia != null)
  39. {
  40. this.mediaCurPos = this.posMedia.CurrentPosition;
  41. }
  42. return (int)this.mediaCurPos;
  43. }
  44. }
  45. public string MediaDuration2
  46. {
  47. get
  48. {
  49. return this.getLengthWithFormat((int)this.mediaDuration);
  50. }
  51. }
  52. public string MediaCurPos2
  53. {
  54. get
  55. {
  56. if (this.posMedia != null)
  57. {
  58. this.mediaCurPos = this.posMedia.CurrentPosition;
  59. }
  60. return this.getLengthWithFormat((int)this.mediaCurPos);
  61. }
  62. }
  63. public int MediaVol
  64. {
  65. get
  66. {
  67. return this.mediaVolum / 50;
  68. }
  69. set
  70. {
  71. this.mediaVolum = value * 50;
  72. if (this.volMedia != null)
  73. {
  74. this.volMedia.Volume = this.mediaVolum;
  75. }
  76. }
  77. }
  78. private void clearUp()
  79. {
  80. if (this.ctlMedia != null)
  81. {
  82. this.ctlMedia.Stop();
  83. }
  84. this.mediaStatus = 1;
  85. this.mediaDuration = 0.0;
  86. this.mediaCurPos = 0.0;
  87. if (this.eexMedia != null)
  88. {
  89. this.eexMedia.SetNotifyWindow(0, 0, 0);
  90. }
  91. if (this.ctlMedia != null)
  92. {
  93. this.ctlMedia = null;
  94. }
  95. if (this.volMedia != null)
  96. {
  97. this.volMedia = null;
  98. }
  99. if (this.posMedia != null)
  100. {
  101. this.posMedia = null;
  102. }
  103. if (this.eexMedia != null)
  104. {
  105. this.eexMedia = null;
  106. }
  107. if (this.objMedia != null)
  108. {
  109. this.objMedia = null;
  110. }
  111. }
  112. public void CloseMedia()
  113. {
  114. this.clearUp();
  115. }
  116. public void RenderMedia(string mediaFileName, bool run)
  117. {
  118. this.clearUp();
  119. try
  120. {
  121. this.objMedia = new QuartzTypeLib.FilgraphManager();
  122. this.objMedia.RenderFile(mediaFileName);
  123. this.volMedia = (this.objMedia as IBasicAudio);
  124. this.posMedia = (this.objMedia as IMediaPosition);
  125. this.ctlMedia = this.objMedia;
  126. this.eexMedia = (this.objMedia as IMediaEventEx);
  127. this.eexMedia.SetNotifyWindow((int)base.Handle, 32769, 0);
  128. this.mediaStatus = 1;
  129. this.mediaDuration = this.posMedia.Duration;
  130. this.volMedia.Volume = this.mediaVolum;
  131. if (run)
  132. {
  133. this.Play();
  134. }
  135. }
  136. catch
  137. {
  138. // MessageBoxCustom.Show("ÎÞ·¨ÕÒµ½²¥·ÅÎļþ!");
  139. return;
  140. //this.clearUp();
  141. }
  142. }
  143. public void Play()
  144. {
  145. this.ctlMedia.Run();
  146. this.mediaStatus = 3;
  147. }
  148. public void Pause()
  149. {
  150. this.ctlMedia.Pause();
  151. this.mediaStatus = 2;
  152. }
  153. public void Stop()
  154. {
  155. this.ctlMedia.Stop();
  156. this.posMedia.CurrentPosition = 0.0;
  157. this.mediaStatus = 1;
  158. }
  159. public void Seek(int posTar)
  160. {
  161. this.posMedia.CurrentPosition = (double)posTar;
  162. }
  163. protected override void WndProc(ref Message m)
  164. {
  165. if (m.Msg == 32769)
  166. {
  167. try
  168. {
  169. while (true)
  170. {
  171. int lEventCode;
  172. int lParam;
  173. int lParam2;
  174. this.eexMedia.GetEvent(out lEventCode, out lParam, out lParam2, 0);
  175. this.eexMedia.FreeEventParams(lEventCode, lParam, lParam2);
  176. if (lEventCode == 1)
  177. {
  178. this.ctlMedia.Stop();
  179. this.posMedia.CurrentPosition = 0.0;
  180. this.mediaStatus = 1;
  181. }
  182. }
  183. }
  184. catch (Exception)
  185. {
  186. }
  187. }
  188. base.WndProc(ref m);
  189. }
  190. private string getLengthWithFormat(int len)
  191. {
  192. int nh = len / 3600;
  193. int nm = (len - nh * 3600) / 60;
  194. int ns = len - (nh * 3600 + nm * 60);
  195. return string.Format("{0:D2}:{1:D2}:{2:D2}", nh, nm, ns);
  196. }
  197. }
  198. }