Ver Fonte

bugFix h5试看视频播放兼容

谢杰标 há 2 anos atrás
pai
commit
65bf4c1937
2 ficheiros alterados com 91 adições e 29 exclusões
  1. 1 0
      pages/learn/index.vue
  2. 90 29
      pages3/course/detail.vue

+ 1 - 0
pages/learn/index.vue

@@ -525,6 +525,7 @@ export default {
 						this.$u.toast(res2.msg)
 					}
 					this.allLoading = false
+					this.sysTime = +this.$method.timest()
 				// }
 				uni.hideLoading()
 			}).catch(err => {

+ 90 - 29
pages3/course/detail.vue

@@ -15,7 +15,9 @@
           @click="startVideo"
         ></image>
       </view>
+
       <view v-else class="video_box" style="width: 100%; height: 450rpx">
+        <!-- #ifdef MP-WEIXIN -->
         <polyv-player
           id="playerVideo"
           playerId="playerVideo"
@@ -29,6 +31,10 @@
           :startTime="startTime"
           @statechange="onStateChange"
         ></polyv-player>
+        <!-- #endif -->
+        <!-- #ifdef H5 -->
+        <view v-show="vid" id="player"></view>
+        <!-- #endif -->
       </view>
 
       <view class="cou_title">
@@ -463,7 +469,7 @@ export default {
     },
   },
   onLoad(option) {
-	console.log('option:', option);
+    console.log("option:", option);
     if (option.scene) {
       // scene 生成二维码扫码进来的
       let optObj = {};
@@ -475,23 +481,23 @@ export default {
       this.goodsType = optObj.goodsType || optObj.gt;
       console.log("optObj.sc:", optObj);
       uni.setStorageSync("newUser_sc", optObj.sc);
-	  uni.setStorageSync("shareActivityCode", optObj.sac)
-	  if (optObj.sac && this.$method.isLogin()) {
-		this.editShareActivityCode()
-	  }
+      uni.setStorageSync("shareActivityCode", optObj.sac);
+      if (optObj.sac && this.$method.isLogin()) {
+        this.editShareActivityCode();
+      }
     } else {
       // 小程序正常跳转的
       // this.id => goodsId
       this.id = option.id;
       this.goodsType = option.goodsType || option.gt;
-	  if (option.sac) {
-		uni.setStorageSync("shareActivityCode", option.sac)
-		if (this.$method.isLogin()) {
-			//已登录
-			this.editShareActivityCode()
-      this.getIsBuy(); // 判断是否已经购买过该课程
-		}
-	  }
+      if (option.sac) {
+        uni.setStorageSync("shareActivityCode", option.sac);
+        if (this.$method.isLogin()) {
+          //已登录
+          this.editShareActivityCode();
+          this.getIsBuy(); // 判断是否已经购买过该课程
+        }
+      }
     }
     this.getDetail();
     this.goodsCourseList();
@@ -542,16 +548,22 @@ export default {
           }
         }
       }
+
       if (self.listenSecond > 0) {
         if (self.timer) {
           clearInterval(self.timer);
         }
+        console.log(4654, self.vid);
+        self.vid = self.vid || item.recordingUrl;
         if (self.vid) {
           //切换视频
-          var polyvPlayerContext = self.selectComponent("#playerVideo");
+          // #ifdef H5
+          this.loadPlayerScript(this.loadPlayer);
+          // #endif
+          // #ifdef MP-WEIXIN
+          var polyvPlayerContext = self.selectComponent("#player");
           polyvPlayerContext.changeVid(item.recordingUrl);
-        } else {
-          self.vid = item.recordingUrl;
+          // #endif
         }
 
         self.startStatus = true;
@@ -567,19 +579,20 @@ export default {
     itemWidth() {
       return 100 / this.list.length + "%";
     },
-	// 修改用户活动邀请码
-	editShareActivityCode() {
-		console.log('修改用户活动邀请码');
-		this.$http({
-			url: '/app/user/edit/shareActivityCode',
-        	method: "post",
-			data: {
-				shareActivityCode: uni.getStorageSync("shareActivityCode")
-			}
-		}).then((res) => {
-			if (res.data.code == 200) {}
-		})
-	},
+    // 修改用户活动邀请码
+    editShareActivityCode() {
+      console.log("修改用户活动邀请码");
+      this.$http({
+        url: "/app/user/edit/shareActivityCode",
+        method: "post",
+        data: {
+          shareActivityCode: uni.getStorageSync("shareActivityCode"),
+        },
+      }).then((res) => {
+        if (res.data.code == 200) {
+        }
+      });
+    },
     appCommonGoodsCourseModuleFreeExamList() {
       // url: '/app/common/goods/course/moduleFreeExamList/'+data,
       this.$api.appCommonGoodsCourseModuleFreeExamList(this.id).then((res) => {
@@ -1185,6 +1198,54 @@ export default {
         this.closePop();
       });
     },
+    loadPlayerScript(callback) {
+      if (!window.polyvPlayer) {
+        const myScript = document.createElement("script");
+        myScript.setAttribute(
+          "src",
+          "https://player.polyv.net/script/player.js"
+        );
+        myScript.onload = callback;
+        document.body.appendChild(myScript);
+      } else {
+        callback();
+      }
+    },
+    // 播放视频
+    loadPlayer() {
+      if (this.player) {
+        this.polyvPlayerContext.changeVid(this.vid);
+        return;
+      }
+      const polyvPlayer = window.polyvPlayer;
+      this.$api.polyvVideoSign(this.vid).then(async (res) => {
+        console.log("播放凭证res", res);
+        this.player = await polyvPlayer({
+          wrap: "#player",
+          width: "100%",
+          showLine: "off",
+          height: 218,
+          ban_history_time: "on",
+          vid: this.vid,
+          forceH5: true,
+          autoplay: this.autoplay,
+          speed: this.playbackRate,
+          teaser_show: 1,
+          tail_show: 1,
+          hideSwitchPlayer: true,
+          ts: res.data.data.ts,
+          sign: res.data.data.sign,
+        });
+        this.polyvPlayerContext = this.player;
+      });
+    },
+    clears() {
+      return new Promise((resolve, reject) => {
+        this.vid = "";
+        this.player && this.player.destroy();
+        resolve();
+      });
+    },
   },
 };
 </script>