Here's some sample code to show how easy it is to play an MP3 file using DirectShow:
#include <dshow.h>void main(void){ IGraphBuilder *pGraph; IMediaControl *pMediaControl; IMediaEvent *pEvent; CoInitialize(NULL); // Create the filter graph manager and query for interfaces. CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl); pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); // Build the graph. IMPORTANT: Change string to a file on your system. pGraph->RenderFile(L"C:\\Example.mp3", NULL); // Run the graph. pMediaControl->Run(); // Wait for completion. long evCode; pEvent->WaitForCompletion(INFINITE, &evCode); // Clean up. pMediaControl->Release(); pEvent->Release(); pGraph->Release(); CoUninitialize();}
DirectShow looks very duanting at first due to the sheer number of interfaces but you really need to concern yourself with
IGraphBuilder
, IMediaControl
, IMediaEvent
and IBasicAudio
iterfaces. You can also use it to play other audio file types like AU, AIFF, SND, etc.
- Kaijin
Edited by - Kaijin on January 2, 2002 2:08:31 PM