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