DirectDraw和DirectShow如何协调,正十分迷茫中
[复制链接]
我开发一个游戏,采取独占模式,想在DIRECTDRAWSURFACE表面开辟一块区域用于播放视频,现在是没有办法看见视频播放的画面,
但是如果我把DirectDraw相关的代码去掉,只保留播放视频的代码,视频是能够正常播放的。另外请教高手知道如何使用MediaPlayer控件来进行播放。
主要代码如下:
CoInitialize(NULL);
//初始化DirectDraw等
DDInit(m_hWnd);
//绘制游戏画面
DrawGameBackGrond();
FlipScreen(FULLSCREEN, NULL);
HWND hWnd;
//获取STATIC TEXT句柄,播放视频的容器
hWnd = GetDlgItem(IDC_STATIC_MPEG)->m_hWnd;
//播放视频
PlayMovieInWindow(hWnd, L"Picture\\M101.mpg");
//播放视频
void PlayMovieInWindow(HWND hWnd, LPCWSTR FileName)
{
HRESULT hr;
// Create the filter graph manager.
hr = CoCreateInstance(CLSID_FilterGraph, NULL,
CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void **)&pGB);
if(SUCCEEDED(hr))
{
// Have the graph construct its the appropriate graph automatically
pGB->RenderFile(FileName, NULL);
// QueryInterface for DirectShow interfaces
pGB->QueryInterface(IID_IMediaControl, (void **)&pMC);
pGB->QueryInterface(IID_IMediaEventEx, (void **)&pME);
pGB->QueryInterface(IID_IMediaSeeking, (void **)&pMS);
// Query for video interfaces, which may not be relevant for audio files
pGB->QueryInterface(IID_IVideoWindow, (void **)&pVW);
pGB->QueryInterface(IID_IBasicVideo, (void **)&pBV);
// Query for audio interfaces, which may not be relevant for video-only files
pGB->QueryInterface(IID_IBasicAudio, (void **)&pBA);
// Is this an audio-only file (no video component)?
CheckVisibility();
if(!g_bAudioOnly)
{
pVW->put_Owner((OAHWND)hWnd);
pVW->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
}
// Have the graph signal event via window callbacks for performance
//pME->SetNotifyWindow((OAHWND)hWnd, WM_GRAPHNOTIFY, 0);
long Width, Height;
pBV->GetVideoSize(&Width, &Height);
pVW->SetWindowPosition(0, 0, Width, Height);
// Run the graph to play the media file
pMC->Run();
g_psCurrent = psRUNNING;
::SetForegroundWindow(hWnd);
::SetWindowPos(hWnd, HWND_TOPMOST, 80, 30, Width, Height, SWP_SHOWWINDOW);
}
}
//下面的代码是从网上看见的,但是
hr = CoCreateInstance(CLSID_AMMultiMediaStream, NULL,
CLSCTX_INPROC_SERVER, IID_IAMMultiMediaStream, (void **)&pAMStream);
hr返回结果是失败,不知道对应的ax文件是哪个,请指教
HRESULT LoadFromFile(const char *szFileName,IMultiMediaStream **ppMMStream, LPDIRECTDRAW4 pDD)
{
HRESULT hr;
IAMMultiMediaStream *pAMStream;
hr = CoCreateInstance(CLSID_AMMultiMediaStream, NULL,
CLSCTX_INPROC_SERVER, IID_IAMMultiMediaStream, (void **)&pAMStream);
if(FAILED(hr))
return hr;
WCHAR wPath[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, szFileName, -1, wPath, sizeof(wPath) / sizeof(wPath[0]));
if(FAILED(hr=pAMStream->Initialize(STREAMTYPE_READ, AMMSF_NOGRAPHTHREAD, NULL)))
return hr;
if(FAILED(hr=pAMStream->AddMediaStream(pDD, &MSPID_PrimaryVideo, 0, NULL)))
return hr;
if(FAILED(hr=pAMStream->AddMediaStream(NULL, &MSPID_PrimaryAudio, AMMSF_ADDDEFAULTRENDERER, NULL)))
return hr;
if(FAILED(hr=pAMStream->OpenFile(wPath, 0)))
return hr;
*ppMMStream = pAMStream;
return S_OK;
}
HRESULT Play(IDirectDrawSurface *pSurface, IMultiMediaStream *pMMStream)
{
IMediaStream *pPrimaryVidStream;
IDirectDrawMediaStream *pDDStream;
IDirectDrawStreamSample *pSample;
RECT rect;
DDSURFACEDESC ddsd;
pMMStream->GetMediaStream(MSPID_PrimaryVideo, &pPrimaryVidStream);
pPrimaryVidStream->QueryInterface(IID_IDirectDrawMediaStream, (void **)&pDDStream);
ddsd.dwSize = sizeof(ddsd);
pDDStream->GetFormat(&ddsd, NULL, NULL, NULL);
rect.top =100;
rect.left =150;
rect.bottom = ddsd.dwHeight+100;
rect.right = ddsd.dwWidth+150;
pDDStream->CreateSample(pSurface, &rect, 0, &pSample);
pMMStream->SetState(STREAMSTATE_RUN);
while(pSample->Update(0, NULL, NULL, NULL) == S_OK);
pMMStream->SetState(STREAMSTATE_STOP);
pSample->Release();
pDDStream->Release();
pPrimaryVidStream->Release();
return S_OK;
}