IGraphBuilder graphBuilder = (IGraphBuilder)new FilterGraph(); IMediaControl mediaControl = (IMediaControl)graphBuilder; IBaseFilter sourceFilter = null; IBaseFilter audioRenderer = null; IBaseFilter videoRenderer = null; // Add source filter to graph graphBuilder.AddSourceFilter("C:\\example.mp4", "Example Video", out sourceFilter); // Create audio and video renderers audioRenderer = (IBaseFilter)new DirectSoundRenderer(); videoRenderer = (IBaseFilter)new VideoRenderer(); // Add filters to graph and connect pins graphBuilder.AddFilter(audioRenderer, "Audio Renderer"); graphBuilder.AddFilter(videoRenderer, "Video Renderer"); graphBuilder.Connect(sourceFilter.FindPin("Audio"), audioRenderer.FindPin("Input")); graphBuilder.Connect(sourceFilter.FindPin("Video"), videoRenderer.FindPin("Input")); // Play media file mediaControl.Run();
IGraphBuilder graphBuilder = (IGraphBuilder)new FilterGraph(); IBaseFilter customFilter = null; IBaseFilter audioRenderer = null; // Add custom filter to graph Type customFilterType = Type.GetTypeFromCLSID(new Guid("{GUID}")); Activator.CreateInstance(customFilterType); // Create audio renderer audioRenderer = (IBaseFilter)new DirectSoundRenderer(); // Add filters to graph and connect pins graphBuilder.AddFilter(customFilter, "Custom Filter"); graphBuilder.AddFilter(audioRenderer, "Audio Renderer"); graphBuilder.Connect(customFilter.FindPin("Output"), audioRenderer.FindPin("Input"));This example demonstrates how to add custom filters to the multimedia graph. First, a new instance of the FilterGraph object is created and cast to an IGraphBuilder interface. Then, the custom filter is added to the graph by creating an instance of the filter type and using the AddFilter method. In this example, the filter is identified by its GUID. Finally, the pins from the custom filter are connected to the audio renderer using the Connect method.