Friday 27 September 2013

Play video as background in window with DirectShow

Play video as background in window with DirectShow

I'm almost there. I want to play a MPEG file as a background video inside
a border-less window. I have the window and just after creating it I add
this code:
// Global vars
IGraphBuilder* g_pGraphBuilder;
IMediaControl* g_pMediaControl;
IMediaEventEx* g_pMediaEvent;
IMediaPosition* g_pMediaPosition;
HWND hWndParent;
// WinMain. Creates the window then executes StartVideoBackground()
// bool StartVideoBackground()
RECT grc;
IVideoWindow *pVidWin = NULL;
HRESULT hr = CoInitialize(NULL);
hr = CoCreateInstance(
CLSID_FilterGraph,
NULL,
CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,
(void**)&g_pGraphBuilder
);
g_pGraphBuilder->QueryInterface(
IID_IMediaControl,
(void**)&g_pMediaControl
);
g_pGraphBuilder->QueryInterface(
IID_IMediaEvent,
(void**)&g_pMediaEvent
);
g_pGraphBuilder->QueryInterface(
IID_IMediaPosition,
(void**)g_pMediaPosition
);
g_pGraphBuilder->QueryInterface(
IID_IVideoWindow,
(void **)&pVidWin
);
pVidWin->put_Owner((OAHWND)hWndParent);
pVidWin->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS);
GetClientRect(hWndParent, &grc);
pVidWin->SetWindowPosition(0, 0, grc.right, grc.bottom);
hr = pVidWin->put_Visible(OAFALSE);
hr = pVidWin->put_Owner(NULL);
if (!FAILED(g_pGraphBuilder->RenderFile(L"Video.mpeg", NULL)))
g_pMediaControl->Run();
I removed some lines that were checking for errors. The idea is that when
starting the application I can see my border-less main window showing up
and also a second window playing the video. What I'd like is the video to
be played inside the main window, without borders, like a background (over
which I will add more controls). Is that possible?

No comments:

Post a Comment