Browse Source

播放器优化

y595705120 4 ngày trước cách đây
mục cha
commit
2a82d4431e
1 tập tin đã thay đổi với 12 bổ sung21 xóa
  1. 12 21
      src/containers/center/play/components/media.vue

+ 12 - 21
src/containers/center/play/components/media.vue

@@ -131,7 +131,6 @@
       },
     },
     created() {
-      this.startTick()
       this.startMonitor()
     },
     methods: {
@@ -167,15 +166,16 @@
           that.reportErr("play", '' + err.message)
         }
       },
-      playerReadied(audio) {
-        console.log("playerReadied", audio)
+      playerReadied(player) {
         let that = this;
+        this.isReady = true
+        setTimeout(() => this.setMarks(), 600);
 
         if (this.media.position > 5 && this.media.position < this.media.duration) {
-          this.setposition(this.media.position)
+          setTimeout(function() {
+            that.setposition(that.media.position)
+          }, 300)
         }
-        this.isReady = true
-        setTimeout(() => this.setMarks(), 600);
 
         setTimeout(() => {
           if (that.player && that.player.volume) {
@@ -210,13 +210,6 @@
       },
       onPlayerError(event) {
         this.reportErr("play", 'error');
-        let player = this.$refs.videoPlayer && this.$refs.videoPlayer.player;
-        if (player) {
-          player.pause();
-          setTimeout(() => {
-            player.play();
-          }, 1000);
-        }
       },
       onPlayerEnded(event) {
         this.reportErr("play", 'end');
@@ -235,13 +228,13 @@
         myPlayer && myPlayer.pause()
       },
       doPlay() {
-        // console.log("doPlay")
         this.onPlay = true
         this.startTick();
         if (!this.$refs.videoPlayer || !this.$refs.videoPlayer.player) return;
         if (!this.dialog) return this.doPause();
         let myPlayer = this.$refs.videoPlayer.player;
-        myPlayer && myPlayer.play()
+        let p = myPlayer && myPlayer.play()
+        if (p && p.catch) p.catch(function() {})
         this.tickNum = 0
       },
       setVolume(val) {
@@ -280,7 +273,7 @@
         document.addEventListener("keydown", function(e) {
           if (e.key == "F12") {
             that.reportErr("play", 'keydownF12');
-            e.preventDefault();
+            try { e.preventDefault() } catch (err) {}
           }
         });
 
@@ -348,12 +341,8 @@
         }
         // 主动暂停
         let myPlayer = this.$refs.videoPlayer.player;
-        let curTimes = parseInt(myPlayer.currentTime());
-        // 后退无心跳
-        if (!force && this.media.position > (curTimes+8)){
-          return;
-        }
 
+        let curTimes = parseInt(myPlayer.currentTime());
         if (curTimes < 4) {
           console.log("curTimes")
           return;
@@ -364,6 +353,7 @@
         //  拉到后面
         if (!isFinish) {
           if (!this.onPlay) return;
+          if(curTimes <= media.position) return;
         }
         if(window.navigator.webdriver){
           this.reportErr("play", 'webdriver');
@@ -411,6 +401,7 @@
 
 <style>
   .video-js {
+    touch-action: none;
     .vjs-control-bar {
       .vjs-icon-custombutton {
         font-family: VideoJS;