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

标签 javascript windows windows-phone-8 camera

我在 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/

相关文章:

c# - 即使在使用任务时也无法等待 'Void'

javascript - 使用表单将变量从 JavaScript 发布到 PHP

javascript - 勾选验证码?

c++ - 64位进程地址的读内存

c++ - 关于原生 C++ 开发的现代书籍

javascript - Phonegap Windows Phone 8 自定义网络字体

javascript - JavaScript 中的按位测试

javascript - 在 Bootstrap + Angular 中显示一个低于另一个的警报

windows - 将JDK换成其他版本问题

c# - VS 2015-WP8- "A specified communication resource (port) is already in use by another application."