what capability must I add to my manifest to enable access to audio devices?

Joe Babb 60 Reputation points
2024-04-23T12:43:43.2+00:00

I am working with Visual Studio 2022 Community edition. Years ago I wrote a program in Win32 that opened an audio device and plotted the signal on the screen. I want to do that same function but now with .NET. When I do a

var endpointId = MediaDevice.GetDefaultAudioRenderId(AudioDeviceRole.Default);

I get a return string. But when I follow that with

var audioModuleManager = new AudioDeviceModulesManager(endpointId);

I get an exception Access Denied. I think I understand that I need to add a capability in my manifest to access audio, but going to the Package.appmanifest under capabilities all I find is "microphone" and clicking that does not help. So why do I get Access Denied when I try to find audio devices and what do I need to add as a capability in order to do so?

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,396 questions
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 33,686 Reputation points Microsoft Vendor
    2024-04-25T02:17:54.27+00:00

    Hi @Joe Babb , Welcome to Microsoft Q&A,

    Because the OP can't mark its own answers, it will be sorted out and sent.

    The solution to the question is as follows:

    I found the answer to my question. It was a matter of adding a restricted capability into the Package.appxmanifest. xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"and<DeviceCapability Name="audioDeviceConfiguration"/> this wasn't easy to find. Apparently MS doesn't like folks working with audio devices.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Joe Babb 60 Reputation points
    2024-04-24T12:11:39.8666667+00:00

    I found the answer to my question. It was a matter of adding a restricted capability into the Package.appxmanifest.

    xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"

    and

    <DeviceCapability Name="audioDeviceConfiguration"/>

    this wasn't easy to find. Apparently MS doesn't like folks working with audio devices.