y595705120 il y a 2 ans
Parent
commit
b5904d7a2b
1 fichiers modifiés avec 28 ajouts et 7 suppressions
  1. 28 7
      src/containers/center/play/components/iMedia.vue

+ 28 - 7
src/containers/center/play/components/iMedia.vue

@@ -49,7 +49,8 @@
         isReady: false,
         isnotbtn: false,
         curTimes: 0,
-        errMsg:'11111',
+        errMsg:'',
+        errCount: 0,
         onPlay: false
       }
     },
@@ -118,11 +119,21 @@
         let param ={id:this.media.id, image: str}
         httpServer("course.collect", param).then(res => {
             let {msg, pause} = res.data
-            if (pause) this.doPause();
-            if ( msg )  this.$message.errorMsg(msg, 2);
+            if ( msg )  this.$message.errorMsg(msg, 10);
             this.errMsg = msg||'';
+            if( msg ){
+              this.errCount ++
+            }else{
+              this.errCount = 0;
+            }
+            if( this.errCount >=2){
+              this.doPause();
+            }
         })
       },
+      destroyTimer(){
+        if (this.timer) clearInterval(this.timer);
+      },
       callCamera() {
         // H5调用电脑摄像头API
         navigator.mediaDevices
@@ -158,7 +169,8 @@
       },
       startTick() {
         let tick = this.tryTick;
-        if (this.timer) clearInterval(this.timer);
+        this.destroyTimer();
+        this.tickNum = 0;
         this.timer = setTimeout(tick, 1 * 1000);
       },
       stopTick() {
@@ -171,7 +183,7 @@
         } catch (err) {
           that.reportErr("play", '' + err.message)
         }
-        if (this.timer) clearInterval(this.timer);
+        this.destroyTimer()
         this.timer = setTimeout(this.tryTick, 1 * 1000);
       },
       playerReadied(audio) {
@@ -238,7 +250,7 @@
         this.tickNum = 0
       },
       onPlayerStart() {
-        // console.log("onPlayerStart")
+        console.log("onPlayerStart")
         this.reportErr("play", 'start');
         this.startTick();
         this.onPlay = true
@@ -274,7 +286,16 @@
           this.$message.errorMsg("需要安装摄像头才能学习", 2);
           return;
         }
-        if( this.tickNum % 60 == 5){
+        if( this.errCount > 3 ){
+          this.$message.errorMsg("人脸不在摄像头上", 5);
+          this.destroyTimer()
+          this.$emit("close");
+          return;
+        }
+        // 异常 10秒检查
+        if ( this.errCount > 0 && this.tickNum % 20 == 1){
+           this.photograph()
+        }else if ( this.tickNum % 60 == 1){
           this.photograph()
         }
         // 每5秒一次心跳