DVD Playback

This page shows you how to playback DVD using directshow. Please note that error handling codes are omitted to keep the sample code simple.

Sample code

The following sample code shows how to do DVD playback. This sample code plays DVD in the DVD drive. If the DVD drive is empty, this sample will not work.


#include <dshow.h>

int
main()
{
 IDvdGraphBuilder *pDvdGraphBuilder;
 IGraphBuilder *pGraphBuilder;
 IMediaControl *pMediaControl;

 CoInitialize(NULL);

 CoCreateInstance(CLSID_DvdGraphBuilder,
	NULL,
	CLSCTX_INPROC_SERVER,
	IID_IDvdGraphBuilder,
	(LPVOID *)&pDvdGraphBuilder);

 AM_DVD_RENDERSTATUS stat;
 pDvdGraphBuilder->RenderDvdVideoVolume(NULL,
     AM_DVD_HWDEC_PREFER, &stat);

 pDvdGraphBuilder->GetFiltergraph(&pGraphBuilder);

 pGraphBuilder->QueryInterface(IID_IMediaControl,
     (LPVOID *)&pMediaControl);

 pMediaControl->Run();

 MessageBox(NULL, "Wait", "dvd test", MB_OK);

 pMediaControl->Stop();

 pMediaControl->Release();
 pGraphBuilder->Release();
 pDvdGraphBuilder->Release();

 CoUninitialize();

 return 0;
}


Simple DVD playback is very easy. But, it is very different from normal file playback. First of all you would have to create a DvdGraphBuilder. And, to create a Graph, you would have to use RenderDvdVideoVolume.

GraphBuilder and MediaControl itself are same as normal file playback, but you would have to use DvdGraphBuilder::GetFiltergraph method to create the Graph.

This DVD playback sample uses MessageBox to block the execution. After the "OK" button is pressed, and MessageBox finishes, the DVD playback will stop.

  

Copyright (C) GeekPage.JP. All rights reserved.