using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace LYFZ.Software.MainBusiness.CallerWizard { public partial class FrmPlayer : LYFZ.Software.UI.CallerWizard.FrmPlayer { public string Path; private Audio ad = null; public FrmPlayer() { } #region 加载 protected override void FrmPlayer_Load(object sender, EventArgs e) { try { ad = new Audio(); updateToolBar(); updateSum(); if (!string.IsNullOrEmpty(Path)) { try { string FileName = Path.ToString(); ad.RenderMedia(FileName, true); trackBar1.Maximum = ad.MediaDuration; updateToolBar(); } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } } catch (Exception ex) { MessageBoxCustom.Show(ex.Message); } } #endregion #region 播放快进 protected override void trackBar1_Scroll(object sender, EventArgs e) { ad.Seek(trackBar1.Value); } #endregion #region 播放 protected override void tsbPlay_Click(object sender, EventArgs e) { try { ad.Play(); updateToolBar(); } catch { MessageBoxCustom.Show("无法找到播放文件!"); } } #endregion #region 暂停 protected override void tsbPause_Click(object sender, EventArgs e) { ad.Pause(); updateToolBar(); } #endregion #region 中止 protected override void tsbStop_Click(object sender, EventArgs e) { ad.Stop(); updateToolBar(); } #endregion #region 打开文件 protected override void tsbOpen_Click(object sender, EventArgs e) { // OpenFileDialog ofd = new OpenFileDialog(); // ofd.Filter = "All Files|*.*"; // if (ofd.ShowDialog() != DialogResult.OK) // return; //// = ofd.FileName.ToString(); // ad.RenderMedia(ofd.FileName, true); // trackBar1.Maximum = ad.MediaDuration; // updateToolBar(); // labelEx1.Text = Application.StartupPath + "\\CallerWizard\\" + Path.ToString(); } #endregion #region 音量快进 protected override void trackBar2_Scroll(object sender, EventArgs e) { ad.MediaVol = trackBar2.Value; } #endregion #region 时间 protected override void timer1_Tick(object sender, EventArgs e) { if (ad.MediaStatus == 3) updateSum(); else if (ad.MediaStatus == 1) { updateToolBar(); updateSum(); } } private void updateSum() { lbSum.Text = string.Format("{0} / {1}", ad.MediaCurPos2, ad.MediaDuration2); trackBar1.Value = ad.MediaCurPos; } #endregion #region 关闭 protected override void FrmPlayer_FormClosing(object sender, FormClosingEventArgs e) { if (ad != null) ad.CloseMedia(); } #endregion #region private void updateToolBar() { trackBar2.Enabled = trackBar1.Enabled = true; switch (ad.MediaStatus) { case 0: trackBar2.Enabled = trackBar1.Enabled = false; tsbPlay.Enabled = false; tsbPause.Enabled = false; tsbStop.Enabled = false; break; case 1: tsbPlay.Enabled = true; tsbPause.Enabled = false; tsbStop.Enabled = false; break; case 2: tsbPlay.Enabled = true; tsbPause.Enabled = false; tsbStop.Enabled = true; break; case 3: tsbPlay.Enabled = false; tsbPause.Enabled = true; tsbStop.Enabled = true; break; } trackBar2.Value = ad.MediaVol; } #endregion } }