本文介绍了如何在我的过滤器图形中添加Default Directsound设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨伙计们:
我是一个关于Default Directsound Device的小谜题。< graphedit / Audio Rederers / Default Directsound Device>
如何在我的过滤器图形中添加Default Directsound设备,以便我的播放器可以正常工作。
任何人有任何想法或用于添加默认DirectSound设备到过滤器图表的链接只是帮助我!
hi guys:
i''m a little puzzle about "Default Directsound Device".< graphedit / Audio Rederers/ Default Directsound Device>
how can i add a Default Directsound Device to my filter graph so that my player can work correctly.
Anyone got any ideas or links for adding the Default DirectSound Device to filter graph just help me!
推荐答案
HRESULT CPlayer::AddDefaultDirectSoundDevice ( IFilterGraph *pfG,IBaseFilter ** ppF,
LPCWSTR wszName)
{
HRESULT hr ;
ICreateDevEnum *pSysDevEnum = NULL;
hr = CoCreateInstance(CLSID_SystemDeviceEnum,NULL,CLSCTX_INPROC_SERVER,
IID_ICreateDevEnum,(void**)&pSysDevEnum);
if(FAILED(hr))
{
return hr;
}
IEnumMoniker *pEnumCat = NULL;
hr = pSysDevEnum->CreateClassEnumerator(CLSID_AudioRendererCategory, &pEnumCat, 0);
if(hr ==S_OK)
{
IMoniker *pMoniker = NULL;
ULONG cFetched;
CString temp ;
while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
IPropertyBag *pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
(void **)&pPropBag);
if (SUCCEEDED(hr))
{
// To retrieve the filter's friendly name, do the following:
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(hr))
{
// Display the name in your UI somehow.
temp.Format(TEXT("%s"),varName.bstrVal);
if(temp.Compare(wszName)==0)
{
// To create an instance of the filter, do the following:
IBaseFilter *pFilter;
hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,
(void**)&pFilter);
// Now add the filter to the graph.
hr = pfG->AddFilter(pFilter,wszName);
if(SUCCEEDED(hr))
*ppF=pFilter ;
else
pFilter->Release();
}
}
VariantClear(&varName);
pPropBag->Release();
}
pMoniker->Release();
}
pEnumCat->Release();
}
pSysDevEnum->Release();
}
已添加< pre>标签以提高可读性 - Code-o-mat [/ EDIT]
Added <pre> tags for better readability - Code-o-mat [/EDIT]
CComPtr<ibasefilter> CreateFilterByName(const WCHAR* filterName, const GUID& category)
{
HRESULT hr = S_OK;
CComPtr<icreatedevenum> pSysDevEnum;
hr = pSysDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum);
if (hrcheck(hr, "Can't create System Device Enumerator"))
{
return NULL;
}
CComPtr<ienummoniker> pEnumCat;
hr = pSysDevEnum->CreateClassEnumerator(category, &pEnumCat, 0);
if (hr == S_OK)
{
CComPtr<imoniker> pMoniker;
ULONG cFetched;
while(pEnumCat->Next(1, &pMoniker, &cFetched) == S_OK)
{
CComPtr<ipropertybag> pPropBag;
hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag, (void * *)&pPropBag);
if (SUCCEEDED(hr))
{
VARIANT varName;
VariantInit(&varName);
hr = pPropBag->Read(L"FriendlyName", &varName, 0);
if (SUCCEEDED(hr))
{
if (wcscmp(filterName, varName.bstrVal)==0)
{
CComPtr<ibasefilter> pFilter;
hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter, (void**)&pFilter);
if (hrcheck(hr, "Can't bind moniker to filter object"))
return NULL;
return pFilter;
}
}
VariantClear(&varName);
}
pMoniker.Release();
}
}
return NULL;
}
使用:
And using:
DEFINE_GUID(CLSID_AudioRenderers,
0xE0F158E1, 0xCB04, 0x11D0, 0xBD, 0x4E, 0x00, 0xA0, 0xC9, 0x11, 0xCE, 0x86);
//add Default DirectSound Device
CComPtr<IBaseFilter> pDefaultDirectSoundDevice = CreateFilterByName(L"Default DirectSound Device", CLSID_AudioRenderers);
hr = pGraph->AddFilter(pDefaultDirectSoundDevice, L"Default DirectSound Device");
CHECK_HR(hr, "Can't add Default DirectSound Device to graph");
这篇关于如何在我的过滤器图形中添加Default Directsound设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!