Browse Source

fix 关闭摄像头异常

Michael Wang 5 năm trước cách đây
mục cha
commit
55d38ab5ae
1 tập tin đã thay đổi với 10 bổ sung6 xóa
  1. 10 6
      src/components/FaceRecognition/FaceRecognition.vue

+ 10 - 6
src/components/FaceRecognition/FaceRecognition.vue

@@ -61,18 +61,22 @@ export default {
     closeCamera: function(newValue) {
       if (newValue) {
         console.log("关闭摄像头");
-        this.$refs.video.srcObject.getTracks().forEach(function(track) {
-          track.stop();
-        });
+        if (this.$refs.video.srcObject) {
+          this.$refs.video.srcObject.getTracks().forEach(function(track) {
+            track.stop();
+          });
+        }
       } else {
         this.openCamera();
       }
     },
   },
   beforeDestroy() {
-    this.$refs.video.srcObject.getTracks().forEach(function(track) {
-      track.stop();
-    });
+    if (this.$refs.video.srcObject) {
+      this.$refs.video.srcObject.getTracks().forEach(function(track) {
+        track.stop();
+      });
+    }
     clearTimeout(this.retrySnapTimeout);
     clearTimeout(this.showSnapResultTimeout);
   },