媒体捕获初始化错误
本文关键字:错误 初始化 媒体 | 更新日期: 2023-09-27 18:12:27
我有一个问题与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);
}
}
返回mediaccapture初始化失败。{0}的错误。最近,它运行良好。但是从今天早上开始,它给出了错误。有人犯过同样的错误吗?
完整的错误信息是;
本系统不支持指定的设备接口级别或特性。: Media Capture初始化失败。{0}线程0x1924已经退出,代码为0 (0x0)。
这里也是一样。经过几个小时的重试和谷歌搜索,我意识到这与windows 10周年更新有关。我在这里找到了解决方案:
https://www.macecraft.com/fix-webcam-issues-windows-10-anniversary-update/我在注册表中添加了EnableFrameServerMode键,网络摄像头神奇地恢复了工作。
但是从今天早上开始,它给出了错误。
你最近更新了你的设备操作系统吗?你在哪个设备上遇到这个问题,操作系统版本是什么?
我个人认为这更像是设备问题或驱动器问题。您可以尝试重新启动设备,看看是否有帮助。或者你可以启动内置的摄像头应用程序,看看这个官方应用程序是否运行良好。
我在这里写这个答案是因为有太多的细节需要确认,请在这里留下评论,告诉我们你的设备的详细信息和根据我的建议你的测试结果,以便我们继续研究这个问题