private void play(string args) { m_FilterManager = new QuartzTypeLib.FilgraphManager(); // m_FilterManager.RenderFile(args); //设置待播放文件 m_VideoWindow = m_FilterManager as QuartzTypeLib.IVideoWindow; //设置播放窗体 m_VideoWindow.Owner = (int)(this.panel1.Handle); m_VideoWindow.WindowStyle &= ~WS_BORDER; m_VideoWindow.SetWindowPosition(0, 0, this.panel1.Width, this.panel1.Height); m_MediaEvent = m_FilterManager as QuartzTypeLib.IMediaEvent; //设置媒体事件 m_MediaEventEx = m_FilterManager as QuartzTypeLib.IMediaEventEx; //设置媒体事件扩展 m_MediaPos = m_FilterManager as QuartzTypeLib.IMediaPosition; //设置媒体位置 m_MediaCtrl = m_FilterManager as QuartzTypeLib.IMediaControl; //设置媒体控制器 }
private void cmdPlay_Click(object sender, EventArgs e) { if (mc == null) { // This audio is being played for the first time. // Load the file. // Access the IMediaControl interface. graphManager = new QuartzTypeLib.FilgraphManager(); mc = (QuartzTypeLib.IMediaControl)graphManager; audio = (QuartzTypeLib.IBasicAudio)graphManager; position = (QuartzTypeLib.IMediaPosition)graphManager; mEventEx = (QuartzTypeLib.IMediaEventEx)graphManager; try { // Choose a file. mc.RenderFile(Application.StartupPath + "\\test.mp3"); mEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0); } catch (FileNotFoundException err) { MessageBox.Show("File not found."); return; } catch (COMException err) { MessageBox.Show("COM error."); return; } } // Start playing the audio asynchronously. try { statusLabel1.Text = "Total: " + ConvertTimeToString((int)position.Duration); mc.Run(); timer1.Start(); } catch (COMException err) { MessageBox.Show("COM error."); } }
private void cmdPlay_Click(object sender, EventArgs e) { if (mc == null) { // This audio is being played for the first time. // Load the file. // Access the IMediaControl interface. graphManager = new QuartzTypeLib.FilgraphManager(); mc = (QuartzTypeLib.IMediaControl)graphManager; audio = (QuartzTypeLib.IBasicAudio)graphManager; position = (QuartzTypeLib.IMediaPosition)graphManager; mEventEx = (QuartzTypeLib.IMediaEventEx)graphManager; try { // Choose a file. mc.RenderFile(Application.StartupPath + "\\test.mp3"); mEventEx.SetNotifyWindow((int)this.Handle, WM_GRAPHNOTIFY, 0); } catch (FileNotFoundException err) { MessageBox.Show("File not found."); return; } catch (COMException err) { MessageBox.Show("COM error."); return; } } // Start playing the audio asynchronously. try { statusLabel1.Text = "Total: " + ConvertTimeToString((int)position.Duration); mc.Run(); timer1.Start(); } catch (COMException err) { MessageBox.Show("COM error."); } }