// //Method to start to play a media file // private void LoadFile(string fName) { try { //get the graph filter ready to render graphBuilder.RenderFile(fName, null); //set the trackbar OABool bCsf, bCsb; mediaPos.CanSeekBackward(out bCsb); mediaPos.CanSeekForward(out bCsf); isSeeking = (bCsb == OABool.True) && (bCsf == OABool.True); if (isSeeking) { trackBar1.Enabled = true; } else { trackBar1.Enabled = false; } trackBar1.Minimum = 0; double duration; mediaPos.get_Duration(out duration); trackBar1.Maximum = (int)(duration * 100.0); Text = fName; //check for the ability to step frameStep = graphBuilder as IVideoFrameStep; if (frameStep.CanStep(1, null) == 0) { canStep = true; buttonFramestep.Enabled = true; } //prepare and set the video window videoWin = graphBuilder as IVideoWindow; videoWin.put_Owner((IntPtr)panel1.Handle); videoWin.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren); Rectangle rc = panel1.ClientRectangle; videoWin.SetWindowPosition(0, 0, rc.Right, rc.Bottom); mediaEvt.SetNotifyWindow((IntPtr)this.Handle, WM_GRAPHNOTIFY, (IntPtr)0); //set the different values for controls trackBar1.Value = 0; minutes = (int)duration / 60; seconds = (int)duration % 60; statusBar1.Panels[0].Text = "Duration: " + minutes.ToString("D2") + ":m" + seconds.ToString("D2") + ":s"; graphState = State.Playing; this.buttonPlay.Text = "Pause"; //start the playback mediaCtrl.Run(); } catch (Exception) { Text = "Error loading file"; } }
protected override bool IsMediaSeekable() { OABool seekFwd = OABool.False, seekBwd = OABool.False; if (mediaPosition != null) { int hr = mediaPosition.CanSeekForward(out seekFwd); DsError.ThrowExceptionForHR(hr); hr = mediaPosition.CanSeekBackward(out seekBwd); DsError.ThrowExceptionForHR(hr); } return(seekFwd != OABool.False && seekBwd != OABool.False); }
void TestCanSeek() { int hr; OABool b, f; hr = m_mediaPosition.CanSeekBackward(out b); DsError.ThrowExceptionForHR(hr); Debug.Assert(b == OABool.True, "CanSeekBackward"); hr = m_mediaPosition.CanSeekForward(out f); DsError.ThrowExceptionForHR(hr); Debug.Assert(f == OABool.True, "CanSeekForward"); }