G10
G10

Reputation: 555

Metro style app media capture exception

I'm writing my first metro-style app. Days ago I've written the code for taking photos based on this sample (here) and it works. With the release of Windows 8 release preview and visual studio 2012 release candidate, the same snippet doesn't work. It seems that there is a problem with the access to camera but in Package.appxmanifest I've checked the webcam capability. the xaml :

<Canvas x:Name="previewCanvas1" Width="320"  Height="240" Background='Gray'>
<Image x:Name="imageElement1"  Width="320" Height="240" Visibility="Collapsed"/>
<CaptureElement x:Name="previewElement1" Width="320" Height="240" />
</Canvas>
<StackPanel Orientation="Horizontal" Margin="20" HorizontalAlignment="Center">
 <Button Width="120" x:Name="btnStartPreview2" Click="btnStartPreview_Click" IsEnabled="true"  Margin="0,0,10,0"  Background="#FFC3C3C3">Da Webcam</Button>
<Button Width="120" x:Name="btnTakePhoto2" Click="btnTakePhoto_Click" IsEnabled="false"  Margin="0,0,10,0"  Background="#FFC3C3C3">Scatta</Button>
</StackPanel>

And the code behind:

MediaCapture mediaCaptureMgr;
async void btnStartPreview_Click(Object sender, RoutedEventArgs e)
        {
            try
            {

                mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
                await mediaCaptureMgr.InitializeAsync();

                previewElement1.Source = mediaCaptureMgr;

                await mediaCaptureMgr.StartPreviewAsync();

            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

the exception is: "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))" but as said, the webcam capability is checked!

Upvotes: 5

Views: 2724

Answers (1)

G10
G10

Reputation: 555

I solved it. To use the webcam you must indicate in package.appxmanifest that the application needs to access the webcam and microphone. Strange but true!

Upvotes: 9

Related Questions