[英]What is the proper way to close a camera in Windows 8 Javascript?
我在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();
您是否看過相機入門套件UWP樣品 ? 它也有JS風味!
如果您希望在完成相機使用后能夠可靠地訪問相機,則需要確保正確清理所有資源。 從您共享的代碼中,您似乎正在讓系統處理此問題,這意味着您的應用可能會在系統完成所有資源之前回來。
你應該照顧:
看看我上面鏈接的示例中的cleanupCameraAsync()方法 ,以獲取有關如何實現它的示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.