wws 2 лет назад
Родитель
Сommit
75f67c1287

BIN
src/assets/test3.mp4


+ 4 - 0
src/components/video-container/PolyvPlayer.vue

@@ -107,4 +107,8 @@ export default {
   transform: rotate(90deg);
 }
 
+/deep/ .player .plv-player-big-play-btn {
+  background: transparent !important;
+}
+
 </style>

+ 161 - 153
src/utils/Player.js

@@ -1,164 +1,172 @@
 export default class Player {
-    player =  null
-    playerId = null
-    vodPlayerJs = 'https://player.polyv.net/resp/vod-player/latest/player.js';
-    vid = '88083abbf5bcf1356e05d39666be527a_8';
-    isPlay = false;
-    url = null
-    isDrag = false;
-    // 回调方法
-    callbackMap = {}
-
-
-    constructor(url) {
-        this.playerId = `player_${Math.random().toString(36).substr(2, 15)}`;
-        this.url = url;
-    }
-
-    // 注册点播播放器
-    loadPlayerScript() {
-        return new Promise((resolve) => {
-            if (!window.polyvPlayer) {
-                const myScript = document.createElement('script');
-                myScript.setAttribute('src', this.vodPlayerJs);
-                myScript.onload = () => {
-                    resolve();
-                };
-                document.body.appendChild(myScript);
-            } else {
-                resolve();
-            }
+  player = null
+  playerId = null
+  vodPlayerJs = 'https://player.polyv.net/resp/vod-player/latest/player.js';
+  vid = '88083abbf5bcf1356e05d39666be527a_8';
+  isPlay = false;
+  url = null
+  isDrag = false;
+  // 回调方法
+  callbackMap = {}
+
+
+  constructor(url) {
+    this.playerId = `player_${Math.random().toString(36).substr(2, 15)}`;
+    this.url = url;
+  }
+
+  // 注册点播播放器
+  loadPlayerScript() {
+    return new Promise((resolve) => {
+      if (!window.polyvPlayer) {
+        const myScript = document.createElement('script');
+        myScript.setAttribute('src', this.vodPlayerJs);
+        myScript.onload = () => {
+          resolve();
+        };
+        document.body.appendChild(myScript);
+      } else {
+        resolve();
+      }
+    })
+  }
+
+  //
+  loadPlayer() {
+    const polyvPlayer = window.polyvPlayer;
+    this.player = polyvPlayer({
+      wrap: '#' + this.playerId,
+      vid: this.vid,
+      url: this.url,
+      skinLocation: 0,
+      autoplay: false,
+      df: 3,
+      // ban_seek: "on",
+      // hideRepeat: true
+    });
+    this.initPlayer();
+  }
+
+  // 初始化完成监听
+  initPlayer() {
+    this.player.on('s2j_onPlayerInitOver', () => {
+      // 获取视频总时长
+      const totalTime = this.player.j2s_getDuration();
+      console.log("totalTime", totalTime)
+      if (this.callbackMap["player_init_over"]) {
+        this.callbackMap["player_init_over"].forEach((callback) => {
+          callback(totalTime);
         })
-    }
-
-    //
-    loadPlayer() {
-        const polyvPlayer = window.polyvPlayer;
-        this.player  = polyvPlayer({
-            wrap: '#' + this.playerId,
-            vid: this.vid ,
-            url: this.url,
-            skinLocation: 0,
-            autoplay: true,
-            df: 3,
-            ban_seek: "off"
-        });
-        this.initPlayer();
-    }
-
-    // 初始化完成监听
-    initPlayer() {
-        this.player.on('s2j_onPlayerInitOver',() => {
-            // 获取视频总时长
-            const totalTime = this.player.j2s_getDuration();
-            console.log("totalTime", totalTime)
-            if(this.callbackMap["player_init_over"]) {
-                this.callbackMap["player_init_over"].forEach((callback) => {
-                    callback(totalTime);
-                })
-            }
-            // this.$bus.$emit("player_init_over", totalTime);
-        });
-
-        //初次播放触发
-        this.player.on("s2j_onPlayStart", () => {
-            // this.$bus.$emit("player_play_start");
-            if(this.callbackMap["player_play_start"]) {
-                this.callbackMap["player_play_start"].forEach((callback) => {
-                    callback();
-                })
-            }
+      }
+    });
+
+    //初次播放触发
+    this.player.on("s2j_onPlayStart", () => {
+      if (this.callbackMap["player_play_start"]) {
+        this.callbackMap["player_play_start"].forEach((callback) => {
+          callback();
         })
+      }
+    })
+
+    // 开始播放
+    this.player.on("s2j_onVideoPlay", () => {
+      const currentTime = this.player.j2s_getCurrentTime();
+      if (this.isDrag && !this.isPlay) {
+        this.pause();
+        this.isDrag = false;
+      } else {
+        this.isPlay = true;
+      }
 
-        // 开始播放
-        this.player.on("s2j_onVideoPlay", () => {
-            const currentTime = this.player.j2s_getCurrentTime();
-            if(this.isDrag && !this.isPlay) {
-                this.pause();
-                this.isDrag = false;
-            } else {
-                this.isPlay = true;
-            }
-
-            if(this.callbackMap["player_play"]) {
-                this.callbackMap["player_play"].forEach((callback) => {
-                    callback(currentTime);
-                })
-            }
-            // this.$bus.$emit("player_play", currentTime);
+      if (this.callbackMap["player_play"]) {
+        this.callbackMap["player_play"].forEach((callback) => {
+          callback(currentTime);
         })
-
-        // 暂停播放
-        this.player.on("s2j_onVideoPause", () => {
-            // this.$bus.$emit("player_pause");
-            this.isPlay = false;
-            if(this.callbackMap["player_pause"]) {
-                this.callbackMap["player_pause"].forEach((callback) => {
-                    callback();
-                })
-            }
+      }
+    })
+
+    // 暂停播放
+    this.player.on("s2j_onVideoPause", () => {
+      // this.$bus.$emit("player_pause");
+      this.isPlay = false;
+      if (this.callbackMap["player_pause"]) {
+        this.callbackMap["player_pause"].forEach((callback) => {
+          callback();
         })
-
-        // 拖拽监听
-        this.player.on("s2j_onVideoSeek", () => {
-            const currentTime = this.player.j2s_getCurrentTime();
-            this.isDrag = true;
-            if(this.callbackMap["player_drag_seek"]) {
-                this.callbackMap["player_drag_seek"].forEach((callback) => {
-                    callback(currentTime);
-                })
-            }
-
-            if(this.callbackMap["player_play"]) {
-                this.callbackMap["player_play"].forEach((callback) => {
-                    callback(currentTime);
-                })
-            }
-            // this.$bus.$emit("player_drag_seek", currentTime);
-            // this.$bus.$emit("player_play", currentTime);
+      }
+    })
+
+    // 拖拽监听
+    this.player.on("s2j_onVideoSeek", () => {
+      const currentTime = this.player.j2s_getCurrentTime();
+      console.log('拖拽', currentTime);
+      this.isDrag = true;
+      if (this.callbackMap["player_drag_seek"]) {
+        this.callbackMap["player_drag_seek"].forEach((callback) => {
+          callback(currentTime);
         })
-    }
-
-    // 跳转某个时刻播放(秒)
-    handleSeekTo(number) {
-        this.player.j2s_seekVideo(number);
-    }
+      }
 
-    // 切换清晰度
-    handleChangeQuality(number) {
-        this.player.switchBitrate(number);
-    }
-
-    on(key, callback) {
-        if(!this.callbackMap[key]) {
-            this.callbackMap[key] = new Set();
-        }
-        this.callbackMap[key].add(callback);
-    }
-
-    off(key, callback) {
-        if(!this.callbackMap[key]) return;
-        this.callbackMap[key].delete(callback);
-    }
-
-    // 暂停
-    pause() {
-        if(!this.player) return;
-        this.player.j2s_pauseVideo();
-    }
-
-    // 播放
-    play() {
-        if(!this.player) return;
-        this.isPlay = true;
-        this.player.j2s_resumeVideo();
+      if (this.callbackMap["player_play"]) {
+        this.callbackMap["player_play"].forEach((callback) => {
+          callback(currentTime);
+        })
+      }
+      // this.$bus.$emit("player_drag_seek", currentTime);
+      // this.$bus.$emit("player_play", currentTime);
+    })
+
+    // 播放完毕
+    this.player.on("s2j_onPlayOver", (options) => {
+      console.log('播放完毕需要重新播放', options);
+      if(options?.vid) {
+        this.player.changeVid(options);
+        this.play();
+      }
+    })
+  }
+
+  // 跳转某个时刻播放(秒)
+  handleSeekTo(number) {
+    this.player.j2s_seekVideo(number);
+  }
+
+  // 切换清晰度
+  handleChangeQuality(number) {
+    this.player.switchBitrate(number);
+  }
+
+  on(key, callback) {
+    if (!this.callbackMap[key]) {
+      this.callbackMap[key] = new Set();
     }
-
-    // 卸载
-    destroyPlayer() {
-        if (this.player) {
-            this.player.destroy();
-            this.player = null;
-        }
+    this.callbackMap[key].add(callback);
+  }
+
+  off(key, callback) {
+    if (!this.callbackMap[key]) return;
+    this.callbackMap[key].delete(callback);
+  }
+
+  // 暂停
+  pause() {
+    if (!this.player) return;
+    this.player.j2s_pauseVideo();
+  }
+
+  // 播放
+  play() {
+    if (!this.player) return;
+    this.isPlay = true;
+    this.player.j2s_resumeVideo();
+  }
+
+  // 卸载
+  destroyPlayer() {
+    if (this.player) {
+      this.player.destroy();
+      this.player = null;
     }
+  }
 }

+ 4 - 3
src/views/feed/FeedList.vue

@@ -12,11 +12,12 @@ export default {
       currentIndex: 0,
       list: [
           "",
+          require("../../assets/test3.mp4"),
           "https://vod.pipi.cn/fec9203cvodtransbj1251246104/88b228db1397757896486535036/v.f42905.mp4",
           "https://vod.pipi.cn/fec9203cvodtransbj1251246104/b40735381397757895972901262/v.f42905.mp4",
-          "https://vod.pipi.cn/fec9203cvodtransbj1251246104/58e22a191397757897006558193/v.f42905.mp4",
-          "https://vod.pipi.cn/fec9203cvodtransbj1251246104/4678c0f91397757896159245507/v.f42905.mp4",
-          "https://vod.pipi.cn/fec9203cvodtransbj1251246104/a52261541397757896812019138/v.f42905.mp4",
+          // "https://vod.pipi.cn/fec9203cvodtransbj1251246104/58e22a191397757897006558193/v.f42905.mp4",
+          // "https://vod.pipi.cn/fec9203cvodtransbj1251246104/4678c0f91397757896159245507/v.f42905.mp4",
+          // "https://vod.pipi.cn/fec9203cvodtransbj1251246104/a52261541397757896812019138/v.f42905.mp4",
       ],
       touchable: true,
     }

+ 18 - 9
src/views/video/VideoItem.vue

@@ -27,12 +27,16 @@ export default {
       showSetPopup: false,
       showVideoInfo: true,
       fullScreen: false,
-      playerInstance: {}
+      playerInstance: {},
+      isIos: false,
     }
   },
   mounted() {
     this.playerInstance = new Player(this.url);
 
+    // 获取当前环境是不是ios,适配安全区
+    this.isIos = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
+    console.log('isIos', this.isIos)
   },
   methods: {
     // 拖拽时需要隐藏视频信息
@@ -56,13 +60,16 @@ export default {
     },
     currentIndex: {
       handler(index) {
-        if(index === this.tabIndex) {
-          this.playerInstance.play();
-        } else {
-          this.playerInstance.pause();
-        }
+        this.$nextTick(() => {
+          if(index === this.tabIndex) {
+            console.log('执行播放了', index)
+            this.playerInstance.play();
+          } else {
+            this.playerInstance.pause();
+          }
+        })
       },
-      immediate: false,
+      immediate: true,
       deep: true,
     }
   }
@@ -85,12 +92,13 @@ export default {
         ref="player" />
 
 
-    <div class="footer" v-show="!fullScreen">
+    <div class="footer" :style="{bottom: isIos ? '20px' : '0px'}" v-show="!fullScreen" safe-area-inset-bottom>
       <video-info v-show="showVideoInfo" />
       <progress-line
           :playerInstance="playerInstance"
           :on-drag="handleDragLine"
           @full="handleFullScreen" />
+      <van-number-keyboard safe-area-inset-bottom />
     </div>
     <video-set-popup :playerInstance="playerInstance"  v-model="showSetPopup" />
   </div>
@@ -133,7 +141,8 @@ export default {
 .footer {
   width: 100%;
   position: absolute;
-  bottom: 0;
+  //bottom: 20px;
+  bottom: 20px;
   z-index: 99;
 }
 </style>