gcj 3 years ago
parent
commit
07c79abac2

+ 2 - 0
src/components/Adult/Preview.vue

@@ -616,6 +616,8 @@ export default {
     },
     initContextData() {
       const _this = this;
+      //_this.$root.isRecording = false;
+      
       _this.contextData = JSON.parse(JSON.stringify(_this.context));
       _this.queIndex = 0;
       _this.NNPENewWordList = [];

+ 43 - 37
src/components/Adult/preview/Soundrecord.vue

@@ -167,7 +167,10 @@ export default {
     // 开始录音
     microphone() {
       let _this = this;
-      if (!this.microphoneStatus) {
+      
+      if (!_this.microphoneStatus) {
+        _this.hasMicro = "";
+        _this.$root.isRecording = true;
         _this.$emit("getWavblob", null);
         this.$emit("getSelectData", { type: '' });
         // 开始录音
@@ -193,6 +196,7 @@ export default {
       } else {
         this.hasMicro = "normal";
         this.recorder.stop();
+        _this.$root.isRecording = false;
         clearInterval(_this.timer);
         // if (
         //   (this.type && this.type == "normal") ||
@@ -227,44 +231,46 @@ export default {
       }
     },
     playmicrophone(totalTimes) {
-      this.isPlaying = true;
-      if (this.selectIndex || this.selectIndex == 0) {
-        let totalTime = totalTimes;
-        let _this = this;
-        if (!this.audio.paused) {
-          this.audio.pause();
-          clearInterval(_this.timer);
-        } else if (this.audio.paused && _this.oldIndex == _this.selectIndex) {
-          _this.audio.play();
-          if (_this.recordtime == 0) {
-            _this.recordtime = totalTimes;
+      if(this.hasMicro){
+        this.isPlaying = true;
+        if (this.selectIndex || this.selectIndex == 0) {
+          let totalTime = totalTimes;
+          let _this = this;
+          if (!this.audio.paused) {
+            this.audio.pause();
+            clearInterval(_this.timer);
+          } else if (this.audio.paused && _this.oldIndex == _this.selectIndex) {
+            _this.audio.play();
+            if (_this.recordtime == 0) {
+              _this.recordtime = totalTimes;
+              _this.playtime = 0;
+            }
+            _this.timer = setInterval(() => {
+              if (_this.playtime < totalTime) {
+                _this.playtime++;
+                _this.recordtime = totalTime - _this.playtime;
+              } else {
+                clearInterval(_this.timer);
+              }
+            }, 1000);
+          } else {
+            _this.audio.pause();
+            _this.audio.load();
+            _this.audio.src = _this.wavblob;
+            _this.oldIndex = _this.selectIndex;
+            _this.audio.play();
             _this.playtime = 0;
+            _this.recordtime = totalTime;
+            clearInterval(_this.timer);
+            _this.timer = setInterval(() => {
+              if (_this.playtime < totalTime) {
+                _this.playtime++;
+                _this.recordtime = totalTime - _this.playtime;
+              } else {
+                clearInterval(_this.timer);
+              }
+            }, 1000);
           }
-          _this.timer = setInterval(() => {
-            if (_this.playtime < totalTime) {
-              _this.playtime++;
-              _this.recordtime = totalTime - _this.playtime;
-            } else {
-              clearInterval(_this.timer);
-            }
-          }, 1000);
-        } else {
-          _this.audio.pause();
-          _this.audio.load();
-          _this.audio.src = _this.wavblob;
-          _this.oldIndex = _this.selectIndex;
-          _this.audio.play();
-          _this.playtime = 0;
-          _this.recordtime = totalTime;
-          clearInterval(_this.timer);
-          _this.timer = setInterval(() => {
-            if (_this.playtime < totalTime) {
-              _this.playtime++;
-              _this.recordtime = totalTime - _this.playtime;
-            } else {
-              clearInterval(_this.timer);
-            }
-          }, 1000);
         }
       }
     },

+ 39 - 36
src/components/Adult/preview/Soundrecorddiff.vue

@@ -112,6 +112,7 @@ export default {
     microphone() {
       let _this = this;
       if (!this.microphoneStatus) {
+        _this.hasMicro=""
         _this.$emit("getWavblob", null);
         this.$emit("getSelectData", { type: "" });
         // 开始录音
@@ -173,44 +174,46 @@ export default {
       _this.$emit("getMicrophoneStatus", _this.microphoneStatus);
     },
     playmicrophone(totalTimes) {
-      this.isPlaying = true;
-      if (this.selectIndex || this.selectIndex == 0) {
-        let totalTime = totalTimes;
-        let _this = this;
-        if (!this.audio.paused) {
-          this.audio.pause();
-          clearInterval(_this.timer);
-        } else if (this.audio.paused && _this.oldIndex == _this.selectIndex) {
-          _this.audio.play();
-          if (_this.recordtime == 0) {
-            _this.recordtime = totalTimes;
+      if(this.hasMicro){
+        this.isPlaying = true;
+        if (this.selectIndex || this.selectIndex == 0) {
+          let totalTime = totalTimes;
+          let _this = this;
+          if (!this.audio.paused) {
+            this.audio.pause();
+            clearInterval(_this.timer);
+          } else if (this.audio.paused && _this.oldIndex == _this.selectIndex) {
+            _this.audio.play();
+            if (_this.recordtime == 0) {
+              _this.recordtime = totalTimes;
+              _this.playtime = 0;
+            }
+            _this.timer = setInterval(() => {
+              if (_this.playtime < totalTime) {
+                _this.playtime++;
+                _this.recordtime = totalTime - _this.playtime;
+              } else {
+                clearInterval(_this.timer);
+              }
+            }, 1000);
+          } else {
+            _this.audio.pause();
+            _this.audio.load();
+            _this.audio.src = _this.wavblob;
+            _this.oldIndex = _this.selectIndex;
+            _this.audio.play();
             _this.playtime = 0;
+            _this.recordtime = totalTime;
+            clearInterval(_this.timer);
+            _this.timer = setInterval(() => {
+              if (_this.playtime < totalTime) {
+                _this.playtime++;
+                _this.recordtime = totalTime - _this.playtime;
+              } else {
+                clearInterval(_this.timer);
+              }
+            }, 1000);
           }
-          _this.timer = setInterval(() => {
-            if (_this.playtime < totalTime) {
-              _this.playtime++;
-              _this.recordtime = totalTime - _this.playtime;
-            } else {
-              clearInterval(_this.timer);
-            }
-          }, 1000);
-        } else {
-          _this.audio.pause();
-          _this.audio.load();
-          _this.audio.src = _this.wavblob;
-          _this.oldIndex = _this.selectIndex;
-          _this.audio.play();
-          _this.playtime = 0;
-          _this.recordtime = totalTime;
-          clearInterval(_this.timer);
-          _this.timer = setInterval(() => {
-            if (_this.playtime < totalTime) {
-              _this.playtime++;
-              _this.recordtime = totalTime - _this.playtime;
-            } else {
-              clearInterval(_this.timer);
-            }
-          }, 1000);
         }
       }
     },

+ 5 - 0
src/main.js

@@ -65,5 +65,10 @@ new Vue({
   el: '#app',
   router,
   store,
+  data: function () {
+    return {
+      isRecording: false
+    }
+  },
   render: h => h(App)
 })