瀏覽代碼

更丰富的摄像头打开错误提示

Michael Wang 5 年之前
父節點
當前提交
49a6c9d25c
共有 1 個文件被更改,包括 42 次插入7 次删除
  1. 42 7
      src/components/FaceRecognition/FaceRecognition.vue

+ 42 - 7
src/components/FaceRecognition/FaceRecognition.vue

@@ -143,7 +143,22 @@ export default {
             video.srcObject = stream;
             window.__stream = stream;
             try {
-              await video.play();
+              try {
+                await video.play();
+              } catch (error) {
+                if (error.name == "AbortError") {
+                  console.log("AbortError and retry");
+                  await video.play();
+                  window._hmt.push([
+                    "_trackEvent",
+                    "摄像头框",
+                    "摄像头状态",
+                    "摄像头没有正常启用: AbortError 重试成功",
+                  ]);
+                } else {
+                  throw error;
+                }
+              }
               this.disableSnap = false;
               const _openEndTime = Date.now();
               window._hmt.push([
@@ -193,16 +208,36 @@ export default {
           } else {
             errMsg = error;
           }
-          this.$Message.error({
-            content: "无法启用摄像头: " + errMsg,
-            duration: 15,
-            closable: true,
-          });
+
+          if (error.name === "NotReadableError") {
+            this.$Message.error({
+              content: "无法启用摄像头: " + error.name + " 请重试!",
+              duration: 15,
+              closable: true,
+            });
+          } else if (error.name === "NotFoundError") {
+            this.$Message.error({
+              content:
+                "无法启用摄像头: " +
+                error.name +
+                " 没有找到合适的摄像头!请重试或更换摄像头!",
+              duration: 15,
+              closable: true,
+            });
+          } else {
+            this.$Message.error({
+              content: "无法启用摄像头: " + errMsg,
+              duration: 15,
+              closable: true,
+            });
+          }
           window._hmt.push([
             "_trackEvent",
             "摄像头框",
             "摄像头状态",
-            "无法启用摄像头" + errMsg,
+            "无法启用摄像头" +
+              errMsg +
+              (typeof errMsg === "object" ? JSON.stringify(errMsg) : ""),
           ]);
         }
       } else {