void Video::PlayMovie(string path) { IGraphBuilder *pGraph = NULL; IMediaControl *pControl = NULL; IMediaEvent *pEvent = NULL; IVideoWindow *pVideo = NULL; // Initialize the COM library. CoInitialize(NULL); // Create the filter graph manager and query for interfaces. CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGraph); // Build the graph int len; int slength = (int)path.length() + 1; len = MultiByteToWideChar(CP_ACP, 0, path.c_str(), slength, 0, 0); wchar_t* buf = new wchar_t[len]; MultiByteToWideChar(CP_ACP, 0, path.c_str(), slength, buf, len); std::wstring r(buf); delete[] buf; pGraph->RenderFile(LPCWSTR(r.c_str()), NULL); // set the owner window pGraph->QueryInterface(IID_IVideoWindow, (void **) &pVideo); pVideo->put_Owner((OAHWND)window); pVideo->put_WindowStyle( WS_CHILD ); pVideo->put_Left(0); pVideo->put_Top(0); pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl); pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent); pControl->Run(); long evCode; pEvent->WaitForCompletion(-1, &evCode); // release controls pControl->Release(); pEvent->Release(); pGraph->Release(); pVideo->Release(); CoUninitialize(); }
bool CHogVideo::Hog() { if (!m_pGraph && !m_pMediaControl && !m_pVideoWindow) return false; this->UnHog(); HRESULT hr = NULL; IGraphBuilder *pGraph = (IGraphBuilder*) m_pGraph; IMediaControl *pMediaControl = (IMediaControl*) m_pMediaControl; IVideoWindow *pVideoWindow = (IVideoWindow*) m_pVideoWindow; // Build the graph. IMPORTANT: Change string to a file on your system. hr = pGraph->RenderFile(m_wszFilename, NULL); if (SUCCEEDED(hr)) { // Run the graph. hr = pMediaControl->Run(); // Hide the window pVideoWindow->put_WindowState(SW_HIDE); pVideoWindow->put_AutoShow(OAFALSE); pVideoWindow->put_Visible(OAFALSE); pVideoWindow->put_Top(-100); pVideoWindow->put_Left(-100); pVideoWindow->put_Width(0); pVideoWindow->put_Height(0); if (SUCCEEDED(hr)) { // Hog the resource. pMediaControl->Pause(); return true; } else return false; } else return false; }