FrmPlayer.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.Software.MainBusiness.CallerWizard
  10. {
  11. public partial class FrmPlayer : LYFZ.Software.UI.CallerWizard.FrmPlayer
  12. {
  13. public string Path;
  14. private Audio ad = null;
  15. public FrmPlayer()
  16. {
  17. }
  18. #region 加载
  19. protected override void FrmPlayer_Load(object sender, EventArgs e)
  20. {
  21. try
  22. {
  23. ad = new Audio();
  24. updateToolBar();
  25. updateSum();
  26. if (!string.IsNullOrEmpty(Path))
  27. {
  28. try
  29. {
  30. string FileName = Path.ToString();
  31. ad.RenderMedia(FileName, true);
  32. trackBar1.Maximum = ad.MediaDuration;
  33. updateToolBar();
  34. }
  35. catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
  36. }
  37. }
  38. catch (Exception ex) { MessageBoxCustom.Show(ex.Message); }
  39. }
  40. #endregion
  41. #region 播放快进
  42. protected override void trackBar1_Scroll(object sender, EventArgs e)
  43. {
  44. ad.Seek(trackBar1.Value);
  45. }
  46. #endregion
  47. #region 播放
  48. protected override void tsbPlay_Click(object sender, EventArgs e)
  49. {
  50. try
  51. {
  52. ad.Play();
  53. updateToolBar();
  54. }
  55. catch { MessageBoxCustom.Show("无法找到播放文件!"); }
  56. }
  57. #endregion
  58. #region 暂停
  59. protected override void tsbPause_Click(object sender, EventArgs e)
  60. {
  61. ad.Pause();
  62. updateToolBar();
  63. }
  64. #endregion
  65. #region 中止
  66. protected override void tsbStop_Click(object sender, EventArgs e)
  67. {
  68. ad.Stop();
  69. updateToolBar();
  70. }
  71. #endregion
  72. #region 打开文件
  73. protected override void tsbOpen_Click(object sender, EventArgs e)
  74. {
  75. // OpenFileDialog ofd = new OpenFileDialog();
  76. // ofd.Filter = "All Files|*.*";
  77. // if (ofd.ShowDialog() != DialogResult.OK)
  78. // return;
  79. //// = ofd.FileName.ToString();
  80. // ad.RenderMedia(ofd.FileName, true);
  81. // trackBar1.Maximum = ad.MediaDuration;
  82. // updateToolBar();
  83. // labelEx1.Text = Application.StartupPath + "\\CallerWizard\\" + Path.ToString();
  84. }
  85. #endregion
  86. #region 音量快进
  87. protected override void trackBar2_Scroll(object sender, EventArgs e)
  88. {
  89. ad.MediaVol = trackBar2.Value;
  90. }
  91. #endregion
  92. #region 时间
  93. protected override void timer1_Tick(object sender, EventArgs e)
  94. {
  95. if (ad.MediaStatus == 3)
  96. updateSum();
  97. else if (ad.MediaStatus == 1)
  98. {
  99. updateToolBar();
  100. updateSum();
  101. }
  102. }
  103. private void updateSum()
  104. {
  105. lbSum.Text = string.Format("{0} / {1}", ad.MediaCurPos2, ad.MediaDuration2);
  106. trackBar1.Value = ad.MediaCurPos;
  107. }
  108. #endregion
  109. #region 关闭
  110. protected override void FrmPlayer_FormClosing(object sender, FormClosingEventArgs e)
  111. {
  112. if (ad != null)
  113. ad.CloseMedia();
  114. }
  115. #endregion
  116. #region
  117. private void updateToolBar()
  118. {
  119. trackBar2.Enabled = trackBar1.Enabled = true;
  120. switch (ad.MediaStatus)
  121. {
  122. case 0:
  123. trackBar2.Enabled = trackBar1.Enabled = false;
  124. tsbPlay.Enabled = false;
  125. tsbPause.Enabled = false;
  126. tsbStop.Enabled = false;
  127. break;
  128. case 1:
  129. tsbPlay.Enabled = true;
  130. tsbPause.Enabled = false;
  131. tsbStop.Enabled = false;
  132. break;
  133. case 2:
  134. tsbPlay.Enabled = true;
  135. tsbPause.Enabled = false;
  136. tsbStop.Enabled = true;
  137. break;
  138. case 3:
  139. tsbPlay.Enabled = false;
  140. tsbPause.Enabled = true;
  141. tsbStop.Enabled = true;
  142. break;
  143. }
  144. trackBar2.Value = ad.MediaVol;
  145. }
  146. #endregion
  147. }
  148. }