How to use CoreAudio API in Metro app
-
13. dubna 2012 10:41
I write a dll for metro app and desktop app use. The function of the DLL is to discovery Audio Device Topology. We use the WASAPI to discovery all Audio Endpoint. In desktop app the dll is function correctly. But in Metro app when we call interface IConnect member function "GetConnectedTo" it always failed. we got follow error.
GetLastError = 0x05
HResult = 0x80070005
http://msdn.microsoft.com/en-us/library/windows/desktop/dd371061(v=vs.85).aspx
Does WASAPI is allow to called in Metro app? Does here has any sample code address how to use it in Metro app?
Please help me!!!!!! Thanks.
- Upravený Robert.wang 13. dubna 2012 11:04
Všechny reakce
-
13. dubna 2012 19:40Moderátor
Hi Robert,
Parts of WASAPI can be used in Metro style apps, but not all. If you look at the documentation for the various interfaces each will say which environment it applies to. The DeviceTopology interfaces in general and IConnect::GetConnectedTo in particular say "Applies to: desktop apps only" and so are cannot be successfully called from Metro style apps. Contrast this with IAudioClient which is available to Metro style apps and is marked "Applies to: desktop apps | Metro style apps"
--Rob
- Označen jako odpověď James Dailey - MSFTMicrosoft Employee, Moderator 17. dubna 2012 22:05
- Zrušeno označení jako odpověď Robert.wang 18. dubna 2012 2:09
- Označen jako odpověď Robert.wang 18. dubna 2012 2:44
- Zrušeno označení jako odpověď Robert.wang 19. dubna 2012 5:49
- Označen jako odpověď Rob CaplanMicrosoft Employee, Moderator 10. října 2012 20:32
-
18. dubna 2012 2:07
Many APIs it say "Applies to: desktop apps only" but we still can be successfully called from Metro style apps.
Example:
The IMMDeviceEnumerator::EnumAudioEndpoints (IDeviceTopology::GetConnector )method in particular say "Applies to: desktop apps only".
Is this wrote the wrong word on document??
http://msdn.microsoft.com/en-us/library/windows/desktop/dd371400(v=vs.85).aspx
- Upravený Robert.wang 18. dubna 2012 2:13
- Upravený Robert.wang 18. dubna 2012 2:14
- Upravený Robert.wang 18. dubna 2012 2:14
-
18. dubna 2012 2:43
I am confused.
The method IMMDevice::Activate in particular say "Applies to:desktop apps only".
But IAudioEndpointVolume in particular say Applies to: desktop apps | Metro style apps
if IMMDevice::Activate can not be used, how can we get IAudioEndpointVolume interface ?IMMDevice *pDevice=NULL;
hr=pDevice->Activate(__uuidof(IAudioEndpointVolume),CLSCTX_ALL,NULL,(void **)(&pVolumeAPI));
- Upravený Robert.wang 19. dubna 2012 7:32
- Upravený Robert.wang 19. dubna 2012 7:32
- Upravený Robert.wang 19. dubna 2012 7:32
-
19. dubna 2012 23:18Moderátor
The documentation is correct. This API should be stubbed out and should not return valid data. You shouldn't need to use IMMDevice in the WinRT environment.
-James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Označen jako odpověď James Dailey - MSFTMicrosoft Employee, Moderator 19. dubna 2012 23:18
- Upravený James Dailey - MSFTMicrosoft Employee, Moderator 19. dubna 2012 23:21
-
19. dubna 2012 23:28Moderátor
You can get the underlying audio endpoint but you must use the WinRT APIs to access the device.
Platform::String^ id = Windows::Media::Devices::MediaDevice::GetDefaultAudioCaptureId(Windows::Media::Devices::AudioDeviceRole::Console ); Microsoft::WRL::ComPtr<IAudioClient> pAudioClient = NULL; ActivateAudioInterface( id->Data(), __uuidof( IAudioClient ), (void**)&pAudioClient );
I hope this helps,
James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Navržen jako odpověď James Dailey - MSFTMicrosoft Employee, Moderator 19. dubna 2012 23:28
-
20. dubna 2012 1:36
Thanks for your help~~
BUT my DLL is not WinRT DLL ,and we use Win32 DLL to get IMMDevice interface. Is it possibly(use LoadPackageLibrary)?
And if we want change to WinRT DLL did you have more sample code about Core audio use WinRT APIs ?
Ex:
1.IPropertyStore GetValue/SetValue for APO(custome effect).
hr = pDevice->OpenPropertyStore(STGM_READ,&pProperties); PROPVARIANT varName; PropVariantInit(&varName); hr = pProperties->GetValue(PKEY_APO_KEY, &varName);
2.if our audio device is not default could we control it?
3.if we have 2 or more audio endpoints could we streaming to not default default device?
- Upravený Robert.wang 20. dubna 2012 1:51
- Upravený Robert.wang 20. dubna 2012 9:01
-
23. dubna 2012 21:33Moderátor
1) You can only load your DLL from Metro if it doesn't use any APIs that are explicitly banned for use in the Metro environment. Most of the time you will need to modify your DLL so that it uses only the APIs that are allowed from the Metro environment.
2) You can choose what audio device endpoint to instantiate at runtime. You do not have to use the default device. See the following link for more information: http://msdn.microsoft.com/en-us/library/windows/apps/hh464974.aspx
3) I apologize but I don't understand this question. Please rephrase it and I will do what I can to answer it for you.
I hope this helps,
James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
-
26. dubna 2012 3:14
thanks James~
Yes, we can use " FindAllAsync" to enumerate the audio endpoint but i got another problem.
1.Before ActivateAudioInterface i want get a symbolic link to call CreateDeviceAccessInstance to specific our device and now i can not get enough information in DeviceInformationCollection interface.
2.I can not get endpoint type in DeviceInformationCollection interface.
example : Line in ,Mic ,Sperker, Headphone.
Any information you can provide me would be greatly appreciated.
- Upravený Robert.wang 26. dubna 2012 3:23
- Upravený Robert.wang 27. dubna 2012 8:39
-
27. dubna 2012 23:28Moderátor
Hello Robert,
How are you checking for the endpoint type? Are you enumerating through the properties? Is this information not included?
DeviceInformation.Properties
http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.enumeration.deviceinformation.properties.aspxWindows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
-
30. dubna 2012 2:35
We had check that "DeviceInformation.Properties" is not include endpoint type.
Enumerating through the properties as below.
System.Devices.Icon
System.ItemNameDisplay
System.Devices.IsDefault
System.Devices.DeviceInstanceID
System.Devices.InterfaceEnable
-
1. května 2012 22:53Moderátor
Hello Robert,
Yes those are the default. If you want additional properties you need to request them.
// Create a set of two additional properties. var propertiesToRetrieve = new Array(); propertiesToRetrieve.push("System.Devices.InterfaceClassGuid"); propertiesToRetrieve.push("System.Devices.ContainerId"); Windows.Devices.Enumeration.findAllAsync(selectorString, propertiesToRetrieve).then(successCallback, errorCallback);) // Handles successful completion of the findAllAsync method. function successCallback(deviceInformationCollection) { var numDevices = deviceInformationCollection.length; if (numDevices) { for (var i = 0; i < numDevices; i++) { printProperties(document.getElementById("log"), deviceInformationCollection[i].properties); } } } // Handles an error completion of the findAllAsync method. function errorCallback(e) { document.getElementById("statusMessage").innerHTML = "Failed to find devices, error: " + e.message; } function printProperties(log, prop) { log.innerHTML += "property store count is: " + prop.size; var pt = prop.first(); while (pt.hasCurrent) { log.innerHTML += "<br />" + pt.current.key + " := " + pt.current.value; pt.moveNext(); } log.innerHTML += "<br />"; }Code above taken from the following page:
http://msdn.microsoft.com/en-us/library/windows/apps/hh464997.aspx
I hope this helps,
James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/
- Označen jako odpověď James Dailey - MSFTMicrosoft Employee, Moderator 1. května 2012 22:53
-
9. května 2012 10:05
Thanks~I can get endpoint type.
I use FindAllAsync api to enumeration audio interface but it only can get enable endpoint.(Paramter:DeviceClass.AudioRender)
But i also need to get Device (active & Unplugged & disable ).
How can i do that??
-
9. května 2012 21:06Moderátor
Hello Robert, I’m not sure that I understand what data you are looking for. If it doesn't exist when using "find all async" I'm not sure that the data exists at the metro level. However, If I understand your question correctly using the DeviceWatcher class may give you the information you are looking for.
DeviceWatcher class
http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.enumeration.devicewatcher.aspxI hope this helps,
James
Windows Media SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/