我在JavaScript中使用MediaCapture捕捉我的相机。
我有一个带有initCamera函数的Camera类。问题是,如果我尝试在短时间内重新启动相机,我会得到这个错误:Hardware MFT failed to start streaming due to lack of hardware resources.
在Windows 8 Javascript中关闭相机的正确方法是什么?
现在我明白了,这意味着我的相机仍在使用中。我想知道的事情是:
- 如何正确地关闭我的相机
- 如何检查我的相机正在使用或无法使用
下面是一段代码:
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();
});
}
};
当前我重新打开相机的方式是用相机类的新实例覆盖相机实例。
在此先感谢。
你有试过关掉它吗? – Kevin 2015-02-23 09:59:43