如何使用 IGraphBuilder 播放 ogg Vorbis 文件
How to play ogg Vorbis files using IGraphBuilder
我需要编写一个可以在 IGraphBuilder 或任何其他 windows API 的帮助下直接播放 .ogg Vorbis 文件的程序(在 C++/win32 API 中)?
我尝试使用 IGraphBuilder,但这对我不起作用。
示例代码:
IMediaControl *pControl = NULL;
IGraphBuilder *pGraph= NULL;
IMediaEventEx *pEvent= NULL;
IMediaPosition *pMediaPosition= NULL;
hr = ::CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGraph);
if (FAILED(hr)) {
return false;
}
hr = pGraph->AddFilter(pFilter, L"Out");
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
hr = pGraph->QueryInterface(IID_IMediaPosition, (void**)&pMediaPosition);
// Build the graph.
hr = pGraph->RenderFile(mFilePath.c_str()/*"C:\sample.ogg file"*/, NULL);
/* here hr = 0x80040265 so SUCCEEDED(hr) didnt allow it to enter in if condition*/
if (SUCCEEDED(hr)) {
// Run the graph.
hr = pControl->Run();
if (SUCCEEDED(hr)) {
// Wait for completion.
long evCode;
pEvent->WaitForCompletion(INFINITE, &evCode);
}
}
// Clean up in reverse order.
SAFE_RELEASE(pEvent);
SAFE_RELEASE(pControl);
SAFE_RELEASE(pGraph);
pGraph = NULL;
::CoUninitialize();
注意:
上面的语句 hr = pGraph->RenderFile()
returned the hr = 0x80040265 and condition if (SUCCEEDED(hr))
doesn't allow to play it.
如果我不使用此条件,则 pControl->Run()
将以 return ID_OK 执行。但是没有播放扬声器。
请建议 solution/method.
注意HRESULT
个错误代码;他们意味着什么。 MSDN 通常对特定于功能的错误代码很有帮助,例如您得到的错误代码。 (通过足够的 COM 编程,您将能够通过视觉识别像 E_INVALIDARG
这样的常见代码。)如果没有,您可以使用头文件来查明潜在的错误代码。 HRESULT
s 有特定的格式;学习吧!
在IGraphBuilder::RenderFile()
, that HRESULT
maps to VFW_E_UNSUPPORTED_STREAM
, which basically means your setup does not support playing Ogg Vorbis files. You will need to install a filter that allows DirectShow to play Ogg Vorbis files, such as the official one from Xiph.Org的情况下。
我需要编写一个可以在 IGraphBuilder 或任何其他 windows API 的帮助下直接播放 .ogg Vorbis 文件的程序(在 C++/win32 API 中)?
我尝试使用 IGraphBuilder,但这对我不起作用。 示例代码:
IMediaControl *pControl = NULL;
IGraphBuilder *pGraph= NULL;
IMediaEventEx *pEvent= NULL;
IMediaPosition *pMediaPosition= NULL;
hr = ::CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
IID_IGraphBuilder, (void **)&pGraph);
if (FAILED(hr)) {
return false;
}
hr = pGraph->AddFilter(pFilter, L"Out");
hr = pGraph->QueryInterface(IID_IMediaControl, (void **)&pControl);
hr = pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent);
hr = pGraph->QueryInterface(IID_IMediaPosition, (void**)&pMediaPosition);
// Build the graph.
hr = pGraph->RenderFile(mFilePath.c_str()/*"C:\sample.ogg file"*/, NULL);
/* here hr = 0x80040265 so SUCCEEDED(hr) didnt allow it to enter in if condition*/
if (SUCCEEDED(hr)) {
// Run the graph.
hr = pControl->Run();
if (SUCCEEDED(hr)) {
// Wait for completion.
long evCode;
pEvent->WaitForCompletion(INFINITE, &evCode);
}
}
// Clean up in reverse order.
SAFE_RELEASE(pEvent);
SAFE_RELEASE(pControl);
SAFE_RELEASE(pGraph);
pGraph = NULL;
::CoUninitialize();
注意:
上面的语句 hr = pGraph->RenderFile()
returned the hr = 0x80040265 and condition if (SUCCEEDED(hr))
doesn't allow to play it.
如果我不使用此条件,则 pControl->Run()
将以 return ID_OK 执行。但是没有播放扬声器。
请建议 solution/method.
注意HRESULT
个错误代码;他们意味着什么。 MSDN 通常对特定于功能的错误代码很有帮助,例如您得到的错误代码。 (通过足够的 COM 编程,您将能够通过视觉识别像 E_INVALIDARG
这样的常见代码。)如果没有,您可以使用头文件来查明潜在的错误代码。 HRESULT
s 有特定的格式;学习吧!
在IGraphBuilder::RenderFile()
, that HRESULT
maps to VFW_E_UNSUPPORTED_STREAM
, which basically means your setup does not support playing Ogg Vorbis files. You will need to install a filter that allows DirectShow to play Ogg Vorbis files, such as the official one from Xiph.Org的情况下。