WackStr
WackStr

Reputation: 188

Silverlight: webcam not getting activated when deployed on live server

My silverlight page has the following code:

public camera()
{
        InitializeComponent();

        cs.CaptureImageCompleted += new EventHandler<CaptureImageCompletedEventArgs>(cs_CaptureImageCompleted);
        VideoBrush vBrush = new VideoBrush();
        vBrush.SetSource(cs);
        vBrush.Stretch = Stretch.Uniform;
        Cam.Fill = vBrush;
        if (CaptureDeviceConfiguration.RequestDeviceAccess())
        {
            cs.Start();
        }
}

This code works fine when I run the website from within visual studio. However, once I deploy the website and run it on internet explorer I don't even get asked permission to turn the webcam on.

What is going on?

Upvotes: 0

Views: 77

Answers (1)

J&#250;lio Melo
J&#250;lio Melo

Reputation: 321

According to MSDN:

Calling RequestDeviceAccess should be done from the context of a user-initiated event. If a call is made that is not from a user-initiated context, no exception is thrown. However, the dialog is not displayed in this case. The RequestDeviceAccess return value will still return results of any previously granted access request or other condition in this case, but otherwise the call is a no-op.

Thus, you can't call CaptureDeviceConfiguration.RequestDeviceAccess() on your class constructor, but should call it from an user event, like a button click.

You probably called it from a user-initiated event before, while you tested within visual studio. I believe that after you moved your code to a constructor, and then the method returned true because of its previously granted access. But when you published your website, the browser, since you're accessing a different domain, your application doesn't have granted access. That's why it works within visual studio, but not on live server.

Upvotes: 1

Related Questions