Windows 8 app - metro app - Mediacapture InitializeAsync exception Access is Denied

1.5k Views Asked by At

I'm developing an app for Windows 8 that uses audio device but I have a problem with the initializeAsync method. Well..

In the app manifest capabilities I have checked microphone.

In the OnNavigatedTo method I have written:

protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        try
        {                
            var settings = new MediaCaptureInitializationSettings();            
            settings.StreamingCaptureMode = StreamingCaptureMode.Audio;                
            await mediaCaptureMgr.InitializeAsync(settings);                                 
        }
        catch (Exception ex)
        {                                

        }
    }

When I run my app the first time I have the following message:

"Can my app use your microphone?" with two buttons: Allow & Block. If I click Allow the app works good. If I click Block the app crash with Access is Denied exception and I can think that it is right but if I run again my app I receive the same exception another time and not the message. How can I close the audio driver that I have started with InitializeAsync??????? How can I proceed????

I could:

1) Disable block button but I don't know how I can do that. 2) Manage the exception (Ex: If click block button reset audio device so I can see the message again) 3) I don't know....

I have passed my last two days on this problem but I havent found a solution.

Thanks in advance.

Andrea

2

There are 2 best solutions below

0
On

Try add this:

<Capability Name="removableStorage" />
<DeviceCapability Name="webcam" />
<DeviceCapability Name="microphone" />
<DeviceCapability Name="proximity" />

to Capabilities in Package.appxmanifest file.

0
On

Please Set VideoDeviceId Property of MediaCaptureInitializationSettings