Silverlight中的摄像头和麦克风被拒绝访问

时间:2013-10-06 11:07:51

标签: c# .net silverlight webcam microphone

我正在尝试创建一个简单的网络摄像头/麦克风捕获项目,并继续获取“访问被拒绝捕获设备”异常。花了几个小时搜索后,我发现以下代码没有任何偏差:

private System.Windows.Media.CaptureSource CaptureSource { get; set; }

private void LayoutRoot_Loaded (object sender, System.Windows.RoutedEventArgs e)
{
    this.CaptureSource = new System.Windows.Media.CaptureSource();

    this.CaptureSource.VideoCaptureDevice = System.Windows.Media.CaptureDeviceConfiguration.GetDefaultVideoCaptureDevice();
    this.CaptureSource.VideoCaptureDevice.DesiredFormat = this.CaptureSource.VideoCaptureDevice.SupportedFormats.FirstOrDefault(f => ((((int) f.FramesPerSecond) == 30) && (f.PixelWidth == 640) && (f.PixelHeight == 480)));

    this.CaptureSource.AudioCaptureDevice = System.Windows.Media.CaptureDeviceConfiguration.GetDefaultAudioCaptureDevice();
    this.CaptureSource.AudioCaptureDevice.DesiredFormat = this.CaptureSource.AudioCaptureDevice.SupportedFormats.FirstOrDefault(f => ((((int) f.BitsPerSample) == 16) && (f.SamplesPerSecond == 44100) && (f.Channels == 2) && (f.WaveFormat == System.Windows.Media.WaveFormatType.Pcm)));

    if ((System.Windows.Media.CaptureDeviceConfiguration.AllowedDeviceAccess) || (System.Windows.Media.CaptureDeviceConfiguration.RequestDeviceAccess()))
    {
        this.CaptureSource.CaptureImageCompleted += CaptureSource_CaptureImageCompleted;
        this.CaptureSource.CaptureFailed += CaptureSource_CaptureFailed;

        this.CaptureSource.Start();
    }
    else
    {
        System.Windows.MessageBox.Show("We do not have permission to access your capture devices.", "Review Track", System.Windows.MessageBoxButton.OK);
    }
}

许多线程都提到在没有附加调试器的情况下运行应用程序。但是,在我的情况下,无论我做什么,Silverlight都不显示相机/麦克风权限对话框,只是在存在调试器的情况下无声地崩溃或引发异常。

我已经尝试过VS2010,VS2013,Windows 7,8和8.1。我甚至尝试对HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Silverlight \ AllowWebcam = 0x00000001进行注册表更改。没效果。

另一篇文章建议对silverlight组策略进行更改,但似乎并没有出现在我的任何系统上。我有Chrome和IE的最新升级,操作系统是最新的,Solverlight是版本5.1.20513.0。不确定是否重要,但我的所有机器都是64位。

0 个答案:

没有答案