Silverlight 4 webcam permission to download User Control

I am using Silverlight 4 to access a webcam. Everything works fine, when I start the webcam in an event with the click of a button, I get an invitation to get permission. I want the webcam to start when user control loads, but for some reason, when I run the same code in the Loaded event, I do not get an invitation when the following code is executed: '

CaptureDeviceConfiguration.RequestDeviceAccess ()

Does anyone have a job to do this?

+5
source share
2 answers

I found a workaround to the problem. I automatically click a button that starts webcam tracking in the Loaded event of the control.

ButtonAutomationPeer peer = new ButtonAutomationPeer(btnStartWebcam);
IInvokeProvider invokeProv = 
    peer.GetPattern(PatternInterface.Invoke) 
    as IInvokeProvider;
invokeProv.Invoke();

, . , , .

+2

. .

Click.

:

public void StartCam()
{
  VideoCaptureDevice dev = CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
  if(CaptureDeviceConfiguration.RequestDeviceAccess() &&
     CaptureDeviceConfiguration.AllowedDeviceAccess)
  {
    CaptureSource capture = new CaptureSource();
    capture.VideoCaptureDevice = dev;

    VideoBrush videoBrush = new VideoBrush();
    videoBrush.SetSource(capture);

    capture.Start();

    WebCamRectangle.Fill = videoBrush;
  }
}

private void button1_Click(object sender, RoutedEventArgs e)
{
  StartCam();
}

Xaml:

<Grid x:Name="LayoutRoot" Background="White">
    <Grid.RowDefinitions>
        <RowDefinition Height="49*" />
        <RowDefinition Height="251*" />
    </Grid.RowDefinitions>
    <Rectangle Name="WebCamRectangle" 
               Stroke="Black" StrokeThickness="1" Grid.Row="1" />
    <Button Content="Start" Height="25" HorizontalAlignment="Left" 
            Margin="12,12,0,0" Name="button1" VerticalAlignment="Top"
            Width="135" Click="button1_Click" />
</Grid>
+1

All Articles