Posted on 2013-01-22 09:33
盛胜 阅读(338)
评论(0) 编辑 收藏 引用
IGraphBuilder *m_pGraph ;
IMediaControl *m_pControl ;
IMediaEvent *m_pEvent ;
CString strfilepath;
CFileDialog FileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_FILEMUSTEXIST,"Video Files(*.avi;*.avi)|*.avi;*.avi||");
if(FileDlg.DoModal()==IDOK)
{
strfilepath = FileDlg.GetPathName();
}
else
{
return ;
}
m_bstr = strfilepath;
m_pGraph = NULL;
m_pControl = NULL;
m_pEvent = NULL;
// Initialize the COM library.
m_hr = CoInitialize(NULL);
if (FAILED(m_hr))
{
printf("ERROR - Could not initialize COM library");
return;
}
// Create the filter graph manager and query for interfaces.
m_hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&m_pGraph);
if (FAILED(m_hr))
{
printf("ERROR - Could not create the Filter Graph Manager.");
return;
}
m_hr = m_pGraph->QueryInterface(IID_IMediaControl, (void **)&m_pControl);
m_hr = m_pGraph->QueryInterface(IID_IMediaEvent, (void **)&m_pEvent);
// Build the graph. IMPORTANT: Change this string to a file on your system.
m_hr = m_pGraph->RenderFile(m_bstr, NULL);
if (SUCCEEDED(m_hr))
{
// Run the graph.
m_hr = m_pControl->Run();
if (SUCCEEDED(m_hr))
{
// Wait for completion.
long evCode;
m_pEvent->WaitForCompletion(INFINITE, &evCode);
// Note: Do not use INFINITE in a real application, because it
// can block indefinitely.
}
}
m_pControl->Release();
m_pEvent->Release();
m_pGraph->Release();
CoUninitialize();