public static void startSecond() { initDSArrays(); filter1 = (DirectShowLib.IBaseFilter) new DirectShowLib.VideoMixingRenderer9(); DirectShowLib.IVMRFilterConfig9 filterConfig = (DirectShowLib.IVMRFilterConfig9)filter1; filterConfig.SetRenderingMode(VMR9Mode.Renderless); filterConfig.SetNumberOfStreams(2); DirectShowLib.IVMRSurfaceAllocatorNotify9 vmrSurfAllocNotify = (DirectShowLib.IVMRSurfaceAllocatorNotify9)filter1; try { int hr = vmrSurfAllocNotify.AdviseSurfaceAllocator(userId1, allocator); DsError.ThrowExceptionForHR(hr); hr = allocator.AdviseNotify(vmrSurfAllocNotify); DsError.ThrowExceptionForHR(hr); } catch { } graph1 = (DirectShowLib.IGraphBuilder) new DirectShowLib.FilterGraph(); graph1.AddFilter(filter1, "Video Mixing Renderer 9"); graph1.RenderFile(@"C:\Download\workmates.wmv", null); mediaControl1 = (DirectShowLib.IMediaControl)graph1; mediaControl1.Run(); }
/// <summary> /// Load a video to setup DirectShow. This also initally creates an instance of the DirectX3D Device /// </summary> public static void StartGraph() { int hr = 0; //CloseGraph(); string path = @"opensebj.wmv"; try { graph = (DirectShowLib.IGraphBuilder) new DirectShowLib.FilterGraph(); filter = (DirectShowLib.IBaseFilter) new DirectShowLib.VideoMixingRenderer9(); DirectShowLib.IVMRFilterConfig9 filterConfig = (DirectShowLib.IVMRFilterConfig9)filter; hr = filterConfig.SetRenderingMode(VMR9Mode.Renderless); DsError.ThrowExceptionForHR(hr); hr = filterConfig.SetNumberOfStreams(2); DsError.ThrowExceptionForHR(hr); SetAllocatorPresenter(); hr = graph.AddFilter(filter, "Video Mixing Renderer 9"); DsError.ThrowExceptionForHR(hr); hr = graph.RenderFile(path, null); DsError.ThrowExceptionForHR(hr); mediaControl = (DirectShowLib.IMediaControl)graph; } catch { } }
//public static void reStartVideo(int videoFile) //{ // // This is a bug - the second time it is executed a new unrequested window pops up. // //mediaControl.Stop(); // //graph.RenderFile(@"C:\temp\test1.avi", null); // //mediaControl = (DirectShowLib.IMediaControl)graph; // //mediaControl.Run(); // // Need to check that the video file has been played, otherwise seting the position // // back to 0 does nothing // if (videoPlayed[videoFile] == false) // { // videoPlayed[videoFile] = true; // int hr = mediaControl.Run(); // DsError.ThrowExceptionForHR(hr); // } // // If not disposed we can just reset the position, the clip never stops playing by the // // looks of this - which is interesting in itself ;-) // seekControl = (DirectShowLib.IMediaPosition)graph; // seekControl.put_CurrentPosition(0); // double duration = 0; // seekControl.get_Duration(out duration); // //fUtil.setDuration((int)duration); // //Finding the framerate // double frameRate = 0; // // Find out the details of the media file // mediaDetail = (DirectShowLib.DES.IMediaDet)new DirectShowLib.DES.MediaDet(); // // Set the name // mediaDetail.put_Filename(@"C:\temp\test1.avi"); // // Read from stream zero // mediaDetail.put_CurrentStream(0); // mediaDetail.get_FrameRate(out frameRate); // //fUtil.setFrameRate((int)frameRate); // //System.Windows.Forms.MessageBox.Show(frameRate.ToString() + " frame rate"); // //seekControl.get_Rate(out playBackRate); // //System.Windows.Forms.MessageBox.Show(duration.ToString() + " in seconds duration"); // //System.Windows.Forms.MessageBox.Show(playBackRate.ToString() + " playback rate"); //} #endregion public static void initDSArrays() { for (int i = 0; i < 255; i++) { dsUserId[i] = new IntPtr(i); } // Setup the array (full 255 positions) to be able to store the videos for (int i = 0; i < 255; i++) { dsFilter[i] = (DirectShowLib.IBaseFilter) new DirectShowLib.VideoMixingRenderer9(); DirectShowLib.IVMRFilterConfig9 filterConfig = (DirectShowLib.IVMRFilterConfig9)dsFilter[i]; filterConfig.SetRenderingMode(VMR9Mode.Renderless); filterConfig.SetNumberOfStreams(2); DirectShowLib.IVMRSurfaceAllocatorNotify9 vmrSurfAllocNotify = (DirectShowLib.IVMRSurfaceAllocatorNotify9)dsFilter[i]; try { int hr = vmrSurfAllocNotify.AdviseSurfaceAllocator(dsUserId[i], allocator); DsError.ThrowExceptionForHR(hr); hr = allocator.AdviseNotify(vmrSurfAllocNotify); DsError.ThrowExceptionForHR(hr); } catch { } dsGraph[i] = (DirectShowLib.IGraphBuilder) new DirectShowLib.FilterGraph(); dsGraph[i].AddFilter(dsFilter[i], "Video Mixing Renderer 9"); //Throw in a call for program updates to be handled //eventRender.Program.update(); // The movie can then be loaded at a latter time. If a movie is going to be // loaded and played in an array like this the DoEvents call does need to be made. // //dsGraph[i].RenderFile(@"C:\Download\workmates.wmv", null); //dsMediaControl[i] = (DirectShowLib.IMediaControl)dsGraph[i]; //dsMediaControl[i].Run(); // //eventRender.Program.update(); } }