gpt4 book ai didi

javascript - 在 Windows 8 Javascript 中关闭相机的正确方法是什么?

转载 作者:可可西里 更新时间:2023-11-01 09:28:43 25 4
gpt4 key购买 nike

我在 javascript 中使用 MediaCapture 来捕捉我的相机。
我有一个带有 initCamera 函数的 Camera 类。问题是,如果我尝试在短时间内重新初始化我的相机,我将收到此错误:Hardware MFT failed to start streaming due to lack of hardware resources.

现在我知道这意味着我的相机仍在使用中。我想知道的是:

  • 如何正确关闭相机
  • 如何检查我的相机是否正在使用或不可用

这是一段代码:

function Camera() {
var that = this;
this.mediaCaptureElement = null;

this.initCamera = function() {
if (!that.mediaCaptureElement) {
that.mediaCaptureElement = new Windows.Media.Capture.MediaCapture();

that.mediaCaptureElement.addEventListener("failed", function (e) {
console.warn("The camera has stopped working");
}

that.mediaCaptureElement.initializeAsync().then(function() {
that.mediaCaptureElement.videoDeviceController.primaryUse = Windows.Media.Devices.CaptureUse.photo;
that.getCameraResolution();
that.orientationChanged();
that.startCamera();
});
}
};

我目前重新打开相机的方法是用 Camera 类的新实例覆盖相机实例。

提前致谢。

最佳答案

我在 C# 中使用 MediaCapture 时遇到了同样的问题。

我必须在 StopPreviewAsync 之后调用 Dispose() 才能更正它:

await cameraControler.MediaCaptureInstance.StopPreviewAsync(); cameraControler.MediaCaptureInstance.Dispose();

关于javascript - 在 Windows 8 Javascript 中关闭相机的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28670361/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com