求救:用DirectShow播放视频的时候,播放视频没有图像
TTRUN 2008-02-26 11:31:24 视频窗口在我的程序主窗口的右侧,在程序主窗口全屏的状态下DirectShow播放视频
的时候,播放视频闪烁一下,然后就只有声音没有图像了(在上一个帖子里,多亏朋友
们的帮助已经解决了主窗口是窗口模式下视频不能播放的问题)。
请大家一定再帮我看下。
开了两个帖子,分不够再加.
谢谢了!!!
void cMediaPlayer::Initialize(const char *szName)
{
HRESULT hr;
Free(); //Deletes any previous DirectShow instances
hr = CoCreateInstance(CLSID_FilterGraph, NULL,CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&m_pGraph);
if (!SUCCEEDED(hr))
{
m_pMediaPlayerLog->WriteOut("CoCreateInstance failed");
}
hr = m_pGraph->QueryInterface(IID_IMediaControl, (void **)&m_pControl);
if (!SUCCEEDED(hr))
{
m_pMediaPlayerLog->WriteOut("IID_IMediaControl failed");
}
hr = m_pGraph->QueryInterface(IID_IMediaEventEx, (void **)&m_pEvent);
if (!SUCCEEDED(hr))
{
m_pMediaPlayerLog->WriteOut("IID_IMediaEventEx failed");
}
hr = m_pEvent->SetNotifyWindow((OAHWND)m_hWnd, WM_GRAPHNOTIFY, 0);
if (!SUCCEEDED(hr))
{
m_pMediaPlayerLog->WriteOut("SetNotifyWindow failed");
}
int nLength = strlen(szName);
WCHAR* Path = new wchar_t [nLength + 1];
MultiByteToWideChar(CP_ACP, 0, szName, nLength + 1, Path, nLength + 1);
hr = m_pGraph->RenderFile(Path, NULL);
if (!SUCCEEDED(hr))
{
m_pMediaPlayerLog->WriteOut("RenderFile failed,RESULT:0x%x",hr);
}
hr = m_pGraph->QueryInterface(IID_IVideoWindow, (LPVOID *) &m_pVideoWindow);//得到IVideoWindow接口 )
if (!SUCCEEDED(hr))
{
m_pMediaPlayerLog->WriteOut("IID_IVideoWindow failed");
}
、、此处是在上一个帖子里,按照yxz_lp 的提示改的,
SetWindowLong(m_hWnd,GWL_STYLE,GetWindowStyle(m_hWnd) |WS_CLIPCHILDREN);
hr = m_pVideoWindow->put_Owner((OAHWND)m_hWnd);
if (!SUCCEEDED(hr))
{
m_pMediaPlayerLog->WriteOut("put_Owner failed,RESULT:0x%x",hr);
}
//下面这行代码在上一个帖子里,按照yxz_lp 的提示加的,没加之前,即使在窗口模式下,视频也不能显示,
//一定要鼠标拖动 窗口,视频才能显示。
hr = m_pVideoWindow->put_WindowStyle(WS_CHILD |WS_CLIPCHILDREN |WS_CLIPSIBLINGS);
if (!SUCCEEDED(hr))
{
m_pMediaPlayerLog->WriteOut("put_WindowStyle failed,RESULT:0x%x",hr);
}
hr = m_pVideoWindow->put_MessageDrain((OAHWND)m_hWnd);//将所有消息传给父窗体处理
if (!SUCCEEDED(hr))
{
m_pMediaPlayerLog->WriteOut("put_MessageDrain failed,RESULT:0x%x",hr);
}
hr = m_pVideoWindow->put_Visible(OATRUE);
if (!SUCCEEDED(hr))
{
m_pMediaPlayerLog->WriteOut("put_Visible failed,RESULT:0x%x",hr);
}
RECT grc;
GetClientRect(m_hWnd, &grc);
m_pVideoWindow->SetWindowPosition(289,81,704,585);
m_pVideoWindow->put_Visible(OATRUE);
}
void cMediaPlayer::Play(const char *szName)
{
if (m_bCurrentPlaying)
{
m_pControl->Run();
}
else
{
Initialize(szName);
m_pControl->Run();
m_bCurrentPlaying = true;
PostMessage(m_hWnd,WM_ERASEBKGND,0,0);
::UpdateWindow(m_hWnd);
}
}