1

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

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 位的。

4

0 回答 0