y595705120 21 시간 전
부모
커밋
fdaf2eb101
1개의 변경된 파일35개의 추가작업 그리고 24개의 파일을 삭제
  1. 35 24
      src/containers/center/play/play.vue

+ 35 - 24
src/containers/center/play/play.vue

@@ -122,7 +122,7 @@
         options: {
           controls: true,
           autoplay: true,
-          muted: false,
+          muted: true,
           loop: false,
           preload: "auto",
           language: 'zh-CN',
@@ -224,9 +224,6 @@
             if (!target && this.list.length) {
               target = this.list[0]
             }
-            if (target) {
-              this.loadMedia(target)
-            }
           }
         })
       },
@@ -287,7 +284,6 @@
           mediaUrl = mediaUrl.replace('/ld/', '/hls/');
         }
         this.mediaType = val;
-        this.stopTick()
         this.onPlay = false
         this.curTimes = 0
         this.hasSeeked = false
@@ -299,11 +295,13 @@
         }
       },
       startTick() {
+        console.log("startTick")
         let tick = this.tryTick;
         if (this.timer) clearInterval(this.timer);
         this.timer = setInterval(tick, 5 * 1000);
       },
       stopTick() {
+        console.log("stopTick")
         if (this.timer) clearInterval(this.timer);
       },
       tryTick() {
@@ -321,9 +319,19 @@
           video.addEventListener('enterpictureinpicture', this.onEnterPiP)
           video.addEventListener('leavepictureinpicture', this.onLeavePiP)
         }
+        if (this.media.position > 5 && this.media.position < this.media.duration - 10) {
+          setTimeout(() => {
+            this.setposition(this.media.position)
+          }, 300)
+        }
       },
       onPlayerError(event) {
         console.error("Video error:", event)
+        let player = this.$refs.videoPlayer && this.$refs.videoPlayer.player
+        if (player && player.reset) {
+          player.reset()
+          setTimeout(() => this.safePlay(player), 500)
+        }
       },
       onPlayerTimeupdate(player) {
         let curTimes = player.currentTime();
@@ -340,8 +348,10 @@
         } catch (e) {}
       },
       setposition(position) {
+        if( position < 10) return;
         if (position > this.media.duration) position = this.media.duration;
-        let player = this.$refs.videoPlayer.player;
+        let player = this.$refs.videoPlayer && this.$refs.videoPlayer.player;
+        if (!player || !player.currentTime) return;
         player.currentTime(position);
         this.safePlay(player)
         if (this.media.isFinish) return;
@@ -351,7 +361,7 @@
       },
       onPlayerPause(event) {
         this.reportErr("play", 'pause');
-        this.stopTick()
+        // this.stopTick()
         this.onPlay = false
       },
       onPlayerEnded(event) {
@@ -404,16 +414,9 @@
         this.tickNum = 0
       },
       onPlayerStart() {
+        console.log("onPlayerStart")
         this.reportErr("play", 'start');
-        this.startTick()
         this.onPlay = true
-        if (!this.hasSeeked && this.media.position > 5 && this.media.position < this.media.duration - 10) {
-          this.hasSeeked = true
-          let player = this.$refs.videoPlayer && this.$refs.videoPlayer.player
-          if (player && player.currentTime) {
-            player.currentTime(this.media.position)
-          }
-        }
       },
       toggleMute() {
         this.isMuted = !this.isMuted
@@ -446,12 +449,13 @@
         return 0
       },
       tick(force = false) {
+        console.log("tick")
         let media = this.media;
         this.tickNum++
         if (this.media.isFinish) {
           return;
         }
-        let myPlayer = this.$refs.videoPlayer.player;
+        let myPlayer = this.$refs.videoPlayer && this.$refs.videoPlayer.player;
         if (!myPlayer) return;
         let curTimes = parseInt(this.getPlayerTime());
         this.curTimes = curTimes || 0
@@ -461,9 +465,9 @@
         if (this.media.position > curTimes + 5 && !force) return;
         let isFinish = force ? 1 : 0
         if (curTimes >= media.duration) isFinish = 1;
-        if (!isFinish) {
-          if (!this.onPlay) return;
-        }
+        // if (!isFinish) {
+        //   if (!this.onPlay) return;
+        // }
         if (window.navigator.webdriver) {
           this.reportErr("play", 'webdriver');
           this.doPause()
@@ -486,20 +490,25 @@
             } = res.data
 
             if(closed){
+              that.doPause();
               that.$message.errorMsg(msg, 10)
               return
             }
             if (pause) {
+              that.doPause();
               that.$message.errorMsg(msg, 10)
-              setTimeout(that.playNext(), 10*1000)
+              setTimeout(() => that.playNext(), 10*1000)
               return
             }
             if (!skip) {
-              this.setposition(position)
+              let diff = Math.abs(position - curTimes);
+              if (diff > 3) {
+                that.setposition(position)
+              }
             }
-            Object.assign(this.media, res.data)
+            Object.assign(that.media, res.data)
             if( res.data.isFinish == 1){
-              this.playNext()
+              that.playNext()
             }
           }
         })
@@ -518,6 +527,7 @@
             marks,
             duration
           } = res.data || {};
+          if(position < 10) position = 0;
           this.mediaUrl = mediaUrl;
           this.media.position = position;
           this.media.duration = duration;
@@ -532,9 +542,10 @@
               src: mediaUrl,
               type: "application/x-mpegURL"
             }],
-            playtimes: position || 1,
+            playtimes: position,
             autoplay: true
           }
+          this.startTick()
         });
       }
     },