扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:黎宇 来源:天极网 2007年11月13日
关键字:
图 3 |
OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*"; if (DialogResult.OK == openFileDialog.ShowDialog()) { …. } |
CleanUp(); m_objFilterGraph = new FilgraphManager(); m_objFilterGraph.RenderFile(openFileDialog.FileName); m_objBasicAudio = m_objFilterGraph as IBasicAudio; try { m_objVideoWindow = m_objFilterGraph as IVideoWindow; m_objVideoWindow.Owner = (int) panel1.Handle; m_objVideoWindow.WindowStyle = WS_CHILD | WS_CLIPCHILDREN; m_objVideoWindow.SetWindowPosition(panel1.ClientRectangle.Left, panel1.ClientRectangle.Top, panel1.ClientRectangle.Width, panel1.ClientRectangle.Height); } catch (Exception ex) { m_objVideoWindow = null; } m_objMediaEvent = m_objFilterGraph as IMediaEvent; m_objMediaEventEx = m_objFilterGraph as IMediaEventEx; m_objMediaEventEx.SetNotifyWindow((int) this.Handle, WM_GRAPHNOTIFY, 0); m_objMediaPosition = m_objFilterGraph as IMediaPosition; m_objMediaControl = m_objFilterGraph as IMediaControl; // 如何来播放,暂停,停止? 简单这些函数看字面也知道. // m_objMediaControl.Run();//播放 m_objMediaControl.Pause();//暂停 m_objMediaControl.Stop();//停止 // 这段代码非常简单。当用户单击播放/暂停按钮时,代码将检查 Player 的 playState 属性。如果 Player 正在播放数字媒体文件,代码就会暂停文件的播放; 如果 Player 已经暂停或停止,代码就再次启动 Player 播放文件。 OK,在来看我们是如何控制时间进度的? // private void timer1_Tick(object sender, System.EventArgs e) { if (m_CurrentStatus == MediaStatus.Running) { UpdateStatusBar(); } } |
private void UpdateStatusBar() { switch (m_CurrentStatus) { case MediaStatus.None : statusBarPanel1.Text = "Stopped"; break; case MediaStatus.Paused : statusBarPanel1.Text = "Paused "; break; case MediaStatus.Running: statusBarPanel1.Text = "Running"; break; case MediaStatus.Stopped: statusBarPanel1.Text = "Stopped"; break; } if (m_objMediaPosition != null) { int s = (int) m_objMediaPosition.Duration; int h = s / 3600; int m = (s - (h * 3600)) / 60; s = s - (h * 3600 + m * 60); statusBarPanel2.Text = String.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s); s = (int) m_objMediaPosition.CurrentPosition; h = s / 3600; m = (s - (h * 3600)) / 60; s = s - (h * 3600 + m * 60); statusBarPanel3.Text = String.Format("{0:D2}:{1:D2}:{2:D2}", h, m, s); } else { statusBarPanel2.Text = "00:00:00"; statusBarPanel3.Text = "00:00:00"; } } |
protected override void WndProc(ref Message m) { if (m.Msg == WM_GRAPHNOTIFY) { int lEventCode; int lParam1, lParam2; while (true) { try { m_objMediaEventEx.GetEvent(out lEventCode,out lParam1,out lParam2,0); m_objMediaEventEx.FreeEventParams(lEventCode, lParam1, lParam2); if (lEventCode == EC_COMPLETE) { m_objMediaControl.Stop(); m_objMediaPosition.CurrentPosition = 0; m_CurrentStatus = MediaStatus.Stopped; UpdateStatusBar(); UpdateToolBar(); } } catch (Exception) { break; } } } base.WndProc(ref m); } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者