媒体捕获初始化错误

Media capture initializing error

我在 UWP 媒体捕获初始化方面遇到问题。我的代码在下面,

private async Task StartPreviewAsync()
{
    try
    {
        //set initilize settings
        Settings oneSetting = null;

        using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), sqlpath))
        {
            oneSetting = (from p in conn.Table<Settings>()
                          where p.id == 0
                          select p).FirstOrDefault();
        }

        if (oneSetting.camera != null)
        {
            var settings = new MediaCaptureInitializationSettings();
            settings.StreamingCaptureMode = StreamingCaptureMode.Video;
            settings.PhotoCaptureSource = PhotoCaptureSource.VideoPreview;
            var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);

            foreach (var device in devices)
            {
                if ((device.Id).Equals(oneSetting.cameraId))
                {
                    settings.VideoDeviceId = device.Id;
                    break;
                }
            }

            _mediaCapture = new MediaCapture();
            await _mediaCapture.InitializeAsync(settings);

            //MediaCapture m = new MediaCapture();
            //await m.InitializeAsync();

            var focusSettings = new FocusSettings();
            focusSettings.AutoFocusRange = AutoFocusRange.FullRange;
            focusSettings.Mode = FocusMode.Auto;
            focusSettings.WaitForFocus = true;
            focusSettings.DisableDriverFallback = false;

            _mediaCapture.VideoDeviceController.FocusControl.Configure(focusSettings);
            await _mediaCapture.VideoDeviceController.ExposureControl.SetAutoAsync(true);

            _mediaCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees);
            _mediaCapture.SetRecordRotation(VideoRotation.Clockwise90Degrees);

            capturePreview.Source = _mediaCapture;
            await _mediaCapture.StartPreviewAsync();
            _isPreviewing = true;

            _displayRequest.RequestActive();
            DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape;
        }
    }
    catch (UnauthorizedAccessException)
    {
        // This will be thrown if the user denied access to the camera in privacy settings
        System.Diagnostics.Debug.WriteLine("The app was denied access to the camera");
    }
    catch (Exception ex)
    {
        System.Diagnostics.Debug.WriteLine("MediaCapture initialization failed. {0}", ex.Message);
    }
}

它returns MediaCapture 初始化失败。 {0} 错误。最近,它运行良好。但从今天早上开始,它给出了错误。有没有人犯同样的错误?

完整的错误信息是;

此系统不支持指定的设备接口级别或功能。 : 媒体捕获初始化失败。 {0} 线程 0x1924 已退出,代码为 0 (0x0)。

But since this morning it gives the error.

您最近是否更新了您的设备OS?您是在哪个设备上遇到此问题的?OS 版本是什么?

我个人认为这更像是设备问题或驱动问题。您可以尝试重新启动您的设备,看看是否有帮助。或者您可以启动内置的相机应用程序并检查这个官方应用程序是否运行良好。

我在这里写这个答案是因为有太多的细节需要确认,请在这里留言告诉我们你的设备的详细信息和你根据我的建议测试的结果,这样我们就可以保留调查这个问题。

同样的问题。 经过数小时的重试和谷歌搜索,我意识到它与 windows 10 周年更新有关。 我在这里找到了解决方案:

https://www.macecraft.com/fix-webcam-issues-windows-10-anniversary-update/

我在注册表中添加了 EnableFrameServerMode 键,网络摄像头神奇地恢复了工作。