Sfoglia il codice sorgente

音频播放时间显示bug

Michael Wang 5 anni fa
parent
commit
e9950e5d91

+ 1 - 0
src/features/Login/Login.vue

@@ -755,6 +755,7 @@ export default {
         "艾米秀宝(ImiShowBox)",
         "video2Webcam",
         "飞翔虚拟视频",
+        "魔力秀",
       ];
 
       function checkVCamTxt() {

+ 12 - 5
src/features/OnlineExam/Examing/QuestionAudio.vue

@@ -91,7 +91,7 @@ export default {
             request.response,
             buffer => {
               this.buffer = buffer;
-              this.duration = Number(this.buffer.duration).toFixed(0);
+              this.duration = Math.floor(this.buffer.duration);
               this.downloadPercent = 100;
               // console.log("load ... ");
             },
@@ -110,7 +110,7 @@ export default {
 
       loadDogSound(this.src);
     },
-    play() {
+    async play() {
       if (this.playCount <= 0) {
         console.log("无播放次数");
         return;
@@ -122,19 +122,25 @@ export default {
       this.$emit("played");
       // var audio = new Audio();
       // this.source = this.context.createMediaElementSource(audio); // creates a sound source
+
+      // await this.context.decodeAudioData(this.buffer);
+      this.context.close();
+      this.context = new AudioContext();
       this.source = this.context.createBufferSource(); // creates a sound source
       this.source.buffer = this.buffer; // tell the source which sound to play
       this.source.connect(this.context.destination); // connect the source to the context's destination (the speakers)
       this.source.start(0); // play the source now
       // audio.play();
       this.playing = true;
+      this.currentTime = 0;
       const progress = () => {
         // console.log(context.currentTime, buffer.duration);
-        this.currentTime = Number(this.context.currentTime).toFixed(0);
-        if (this.context.currentTime < this.duration) {
+        this.currentTime = Math.floor(this.context.currentTime);
+        if (this.context.currentTime < this.buffer.duration) {
           requestAnimationFrame(progress);
-        } else if (this.context.currentTime > this.duration) {
+        } else if (this.context.currentTime >= this.buffer.duration) {
           this.currentTime = 0;
+          requestAnimationFrame(progress);
         }
       };
       requestAnimationFrame(progress);
@@ -142,6 +148,7 @@ export default {
       this.source.onended = () => {
         // console.log(e, "ended");
         this.playing = false;
+        this.currentTime = 0;
         // this.$emit("ended", this.name);
       };
     },