This will play MP3's through DirectShow. Most of the source originates from Special Effects Game Programing with DirectX 8. All it needs is a window handle.
Code:
#ifndef CDXSHOWWND
#define CDXSHOWWND
#include <dshow.h>
class CDXShowWnd
{
protected:
IGraphBuilder *m_pGraph;
IVideoWindow *m_pVidWnd;
IMediaControl *m_pMedia;
IMediaEvent *m_pEvent;
HWND m_Hwnd;
public:
CDXShowWnd(void):m_pGraph(NULL),m_pVidWnd(NULL),m_Hwnd(0) {}
virtual ~CDXShowWnd(void)
{
ShutDown();
}
void Create(HWND hwnd)
{
//Create filter graph
CoCreateInstance(CLSID_FilterGraph,NULL,CLSCTX_INPROC,IID_IGraphBuilder,
(void **)&m_pGraph);
m_pGraph->QueryInterface(IID_IVideoWindow,(void **)&m_pVidWnd);
m_pGraph->QueryInterface(IID_IMediaControl,(void **)&m_pMedia);
m_pGraph->QueryInterface(IID_IMediaEvent,(void **)&m_pEvent);
//Set window
m_pVidWnd->put_Owner((OAHWND)hwnd);
m_pVidWnd->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
RECT grc;
::GetClientRect(hwnd,&grc);
m_pVidWnd->SetWindowPosition(0,0,grc.right,grc.bottom);
}
void Play(const unsigned short *File)
{
m_pGraph->RenderFile(File,NULL);
m_pMedia->Run();
long lDone=0;
m_pEvent->WaitForCompletion(0,&lDone);
}
void ShutDown(void)
{
m_pMedia->Release();
m_pEvent->Release();
m_pVidWnd->Release();
m_pGraph->Release();
CoUninitialize();
}
};
#endif
You will need to link with quartz.lib and strmiids.lib and of course have access to dshow.h.
To respond to messages consult the DirectShow SDK on how to use IMediaEvent and callbacks.