i have a sample to play Videos with DirectShow in the XNA Framework. Code:
/// <summary>
/// This method sets up the DirectShow filter graph and obtains the interfaces necessary to control playback
/// for VideoTextures created from video files. This method works for .avi, .mpeg, and .wmv files.
/// </summary>
/// <param name="videoFile">The .avi, .mpeg, or .wmv video file.</param>
private void SetupGraph(string videoFile)
{
try
{
int hr;
// 1. Start building the graph, using FilterGraph and CaptureGraphBuilder2IGraphBuildergraphBuilder=(IGraphBuilder)newFilterGraph();ICaptureGraphBuilder2builder=(ICaptureGraphBuilder2)newCaptureGraphBuilder2();hr=builder.SetFiltergraph(graphBuilder);DsError.ThrowExceptionForHR(hr);// 2. Add the source filter for the video file input.IBaseFiltersourceFilter=null;hr=graphBuilder.AddSourceFilter(videoFile,videoFile,outsourceFilter);DsError.ThrowExceptionForHR(hr);// 3. Get the SampleGrabber interface, configure it, and add it to the graph.ISampleGrabbersampGrabber=(ISampleGrabber)newSampleGrabber();ConfigureSampleGrabber(sampGrabber);hr=graphBuilder.AddFilter((IBaseFilter)sampGrabber,"SampleGrabber");DsError.ThrowExceptionForHR(hr);// 4. Add the null renderer (since we don't want to render in a seperate window.)IBaseFilternullRenderer=(IBaseFilter)newNullRenderer();hr=graphBuilder.AddFilter(nullRenderer,"NullRenderer");DsError.ThrowExceptionForHR(hr);// 5. Render the stream. The way the stream is rendered depends on its type.switch(this.vidType){caseVideoType.AVI:hr=builder.RenderStream(null,null,sourceFilter,(IBaseFilter)sampGrabber,nullRenderer);break;caseVideoType.MPEG:hr=builder.RenderStream(null,null,sourceFilter,(IBaseFilter)sampGrabber,nullRenderer);break;caseVideoType.WMV:hr=builder.RenderStream(null,MediaType.Video,sourceFilter,(IBaseFilter)sampGrabber,nullRenderer);break;default:thrownewException("UnsupportedVideotype:"+this.vidType.ToString());}DsError.ThrowExceptionForHR(hr);// 6. Now that everthing is configured and set up, save the width, height, stride information for use later.SaveSizeInfo(sampGrabber);// 7. Obtain the interfaces that we will use to control the execution of the filter graph.this.mediaControl=graphBuilderasIMediaControl;this.mediaEventEx=graphBuilderasIMediaEventEx;this.mediaSeeking=graphBuilderasIMediaSeeking;}catch(Exceptionex){Console.WriteLine(ex.Message);throwex;}}
Now i want enable the sound, but i dont really know what i have to do. Can anybody help?
Best Regards,
Thorsten
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
i have a sample to play Videos with DirectShow in the XNA Framework. Code:
/// <summary>
/// This method sets up the DirectShow filter graph and obtains the interfaces necessary to control playback
/// for VideoTextures created from video files. This method works for .avi, .mpeg, and .wmv files.
/// </summary>
/// <param name="videoFile">The .avi, .mpeg, or .wmv video file.</param>
private void SetupGraph(string videoFile)
{
try
{
int hr;
Now i want enable the sound, but i dont really know what i have to do. Can anybody help?
Best Regards,
Thorsten
Hi Peter,
thanks. It works fine:-)
Thorsten
Try here:
https://sourceforge.net/forum/message.php?msg_id=3315692
Peter