谢杰标 2 жил өмнө
parent
commit
a119db297b

+ 14 - 6
common/util.js

@@ -24,21 +24,16 @@ export function download(url) {
   // #endif
 }
 
-function saveImgToLoca(url) {
+export function saveImgToLoca(url) {
   uni.downloadFile({
     url: url, //图片地址
     success: ({ statusCode, tempFilePath }) => {
       if (statusCode === 200) {
         const type = tempFilePath.substr(tempFilePath.lastIndexOf(".") + 1);
-        console.log("🚀 ~ file: util.js:32 ~ saveImgToLoca ~ type:", type);
         if (type === "pdf") {
           uni.getFileSystemManager().saveFile({
             tempFilePath,
             success: function (res) {
-              console.log(
-                "🚀 ~ file: util.js:37 ~ uni.getFileSystemManager ~ res:",
-                res
-              );
               uni.showToast({
                 title: "保存成功",
                 icon: "none",
@@ -114,3 +109,16 @@ export function preview(url) {
   });
   // #endif
 }
+
+export function throttle(fn, delay) {
+  let timeout = null;
+  return function () {
+    let args = arguments;
+    if (!timeout) {
+      timeout = setTimeout(() => {
+        timeout = null;
+        fn.apply(this, args);
+      }, delay);
+    }
+  };
+}

+ 13 - 0
components/myPlayer/polyvPlayer.vue

@@ -80,6 +80,7 @@ export default {
       enableAutoRotation: true,
       hasStart: false,
       config: null,
+      Elevideo: null,
     };
   },
   mounted() {
@@ -152,10 +153,18 @@ export default {
       // #ifdef MP-WEIXIN
       polyvPlayerContext.seek(this.videoCurrentTime || 0);
       // #endif
+      // #ifdef H5
+      this.Elevideo = document.querySelector("video.plv-player-video");
+      this.Elevideo &&
+        this.Elevideo.addEventListener("timeupdate", this.timeupdate);
+      // #endif
     },
     playerError(err) {
       console.log("播放err", err);
     },
+    timeupdate(e) {
+      this.$emit("timeupdate", this.playCurrentTime());
+    },
     h5StateChange() {
       let states = {
         s2j_onPlayerInitOver: "onPlayerInitOver", // 播放器初始化完毕时触发
@@ -284,6 +293,10 @@ export default {
     if (polyvPlayerContext) {
       polyvPlayerContext.destroy();
     }
+    // #ifdef H5
+    this.Elevideo &&
+      this.Elevideo.removeEventListener("timeupdate", this.timeupdate, false);
+    // #endif
   },
   computed: {
     vid() {

+ 0 - 155
pages3/live/detail.vue

@@ -66,20 +66,6 @@
             >
           </cover-view>
         </view>
-        <view
-          class="video_box"
-          style="width: 100%; height: 421rpx"
-          v-if="playChannelId > 0"
-        >
-          <player
-            class="plv-mp-demo-player"
-            :videoOption="videoOption"
-            :page-gesture="true"
-            :vslide-gesture="true"
-            :vslide-gesture-in-fullscreen="true"
-            @onLiveStatusChange="playerLiveStatusChange"
-          />
-        </view>
       </view>
       <view class="course_name">
         <view class="course_titles">
@@ -730,7 +716,6 @@ export default {
   data() {
     return {
       hasStart: false,
-      channelItem: null,
       lockTimer: null,
       orderGoodsId: 0,
       noticeShow: false,
@@ -739,9 +724,6 @@ export default {
       seekTime: "",
       toastTimer: null,
       videoToastShow: false,
-      initLiveOk: false,
-      livePlay: false, //是否正在播放直播,不含暂停
-      liveDuration: 0, //直播观看时长
       videoOption: {
         mode: "live",
         uid: "",
@@ -1065,20 +1047,6 @@ export default {
         this.moduleId = arr[0];
         this.chapterId = arr[1];
       });
-      uni.$on("getChannel", (item) => {
-        //清除录播
-        this.hasStart = false;
-        this.$store.commit("setPlayVID", { playVID: null });
-
-        this.moduleId = item.moduleId;
-        this.chapterId = item.chapterId;
-        this.$store.commit("setPlaySectionId", {
-          playSectionId: item.sectionId || item.menuId,
-        });
-        this.getPhotoLastRecord();
-        this.playChannel(item);
-        this.channelItem = item;
-      });
       uni.$on("isRebuild", (item) => {
         this.isRebuild = item;
       });
@@ -1535,129 +1503,6 @@ export default {
         }
       }
     },
-    getLiveUid(channelId) {
-      let self = this;
-      return new Promise((resolve) => {
-        let data = {
-          channelId: channelId,
-          orderGoodsId: this.orderGoodsId,
-        };
-        self.$api.polyvSign(data).then((res) => {
-          resolve(res.data.data);
-        });
-      });
-    },
-    timeEventLiving() {
-      if (plv != null) {
-        if (this.livePlay) {
-          this.liveDuration = this.liveDuration + 1; //每隔1秒
-          if (this.liveDuration == 2) {
-            //直播第2秒拍照
-            // console.log(this.channelItem)
-            // console.log(this.photoHistoryList,'this.photoHistoryList')
-            if (
-              this.goodsPhotographConfig &&
-              this.goodsPhotographConfig.livephotograph == 1 &&
-              this.channelItem.learning != 1 &&
-              this.photoHistoryList.length == 0
-            ) {
-              //开启直播拍照
-              this.openPhoto();
-            } else {
-              this.postStudyRecord(0);
-            }
-          }
-        }
-      }
-    },
-    playerLiveStatusChange(e) {
-      const status = e.detail.status;
-      // console.log("直播状态", status);
-      if (status === "live") {
-        // console.log("开始直播");
-        //开始播放
-        if (this.timer) {
-          clearInterval(this.timer);
-        }
-        this.livePlay = true;
-        this.timer = setInterval(this.timeEventLiving, 1000); //定时器
-      }
-      if (status === "end") {
-        this.hasStart = false;
-        if (this.livePlay) {
-          //只有播放过的结束才提交,避免未开播触发结束
-          this.postStudyRecord(1);
-        }
-        // console.log("结束直播");
-        this.livePlay = false;
-        // 未开始
-      }
-    },
-    closePlv() {
-      if (plv) {
-        plv.destroy();
-      }
-    },
-    playChannel(item) {
-      if (this.timer) {
-        clearInterval(this.timer);
-      }
-      this.startStatus = true;
-      this.initLive();
-    },
-    setLiveOption(status) {
-      const { userId, channelId, recordFileSimpleModel, playbackEnabled } =
-        this.detail;
-      const playRecordFile =
-        playbackEnabled && recordFileSimpleModel && status === "end";
-
-      // if(this.channelItem.sectionType == 3) { //回放
-
-      // 	// this.videoOption = {
-      // 	//   mode: "live",
-      // 	//   uid: this.liveObj.uid, //this.playChannelId  egsxlptzdq
-      // 	//   cid: this.playChannelId,
-      // 	//   openId: this.userInfo.userAccount,
-      // 	//   isAutoChange: false,
-      // 	//   forceVideo: false,
-      // 	// };
-      // } else {  //直播
-
-      this.videoOption = {
-        mode: "live",
-        uid: this.liveObj.uid, //this.playChannelId  egsxlptzdq
-        cid: this.playChannelId,
-        openId: this.userInfo.userAccount,
-        isAutoChange: false,
-        forceVideo: false,
-      };
-      // }
-    },
-    async initLive() {
-      this.liveObj = await this.getLiveUid(this.playChannelId);
-      this.initLiveOk = true;
-      let optionsData = {};
-      optionsData.mode = "live";
-      optionsData.forceVideo = false;
-      optionsData.channelId = this.playChannelId; // 频道ID '2553128'
-      optionsData.openId = this.userInfo.userAccount; // 用户openId  this.userInfo.userAccount 'oQ5eX5BCtSjkE1ct8CzvxGWgh0hQ'
-      optionsData.userId = this.liveObj.uid; // 2.0.0及以上版本的demo需要使用 userId 设置学员唯一id 'egsxlptzdq'
-      let self = this;
-      this.closePlv();
-      plv.init(optionsData).then(({ detail, chat }) => {
-        self.liveDetail = detail;
-
-        // 设置mode为live的videoOption
-        this.setLiveOption();
-        if (detail.isPPT) {
-          chat.on(chat.events.SLICESTART, () => {
-            // 开始直播
-          });
-        } else {
-          plv.api.getOrdinaryLiveStatus(detail.stream);
-        }
-      });
-    },
     openSetting(res) {
       // console.log(res, 98);
     },

+ 11 - 58
pages3/polyv/detail.vue

@@ -27,6 +27,7 @@
           @pause="pause"
           @ended="ended"
           @loadedmetadata="loadedmetadata"
+          @timeupdate="timeupdate"
         ></my-player>
         <view
           class="video_box"
@@ -777,7 +778,6 @@ export default {
         isAutoChange: false,
         forceVideo: false,
       },
-      liveDetail: {},
       showSet: false,
       startStatus: false,
       detail: {},
@@ -1271,7 +1271,6 @@ export default {
       }
       this.clearPauseTimer();
       this.clearBarTimer();
-      this.timer && clearInterval(this.timer);
       if (this.lockTimer) {
         clearInterval(this.lockTimer);
         this.$api
@@ -2098,53 +2097,6 @@ export default {
         plv.destroy();
       }
     },
-    playChannel(item) {
-      if (this.timer) {
-        clearInterval(this.timer);
-      }
-      this.startStatus = true;
-      this.initLive();
-    },
-    setLiveOption(status) {
-      const { userId, channelId, recordFileSimpleModel, playbackEnabled } =
-        this.detail;
-      const playRecordFile =
-        playbackEnabled && recordFileSimpleModel && status === "end";
-
-      this.videoOption = {
-        mode: "live",
-        uid: this.liveObj.uid, //this.playChannelId  egsxlptzdq
-        cid: this.playChannelId,
-        openId: this.userInfo.userAccount,
-        isAutoChange: false,
-        forceVideo: false,
-      };
-    },
-    async initLive() {
-      this.liveObj = await this.getLiveUid(this.playChannelId);
-      this.initLiveOk = true;
-      let optionsData = {};
-      optionsData.mode = "live";
-      optionsData.forceVideo = false;
-      optionsData.channelId = this.playChannelId; // 频道ID '2553128'
-      optionsData.openId = this.userInfo.userAccount; // 用户openId  this.userInfo.userAccount 'oQ5eX5BCtSjkE1ct8CzvxGWgh0hQ'
-      optionsData.userId = this.liveObj.uid; // 2.0.0及以上版本的demo需要使用 userId 设置学员唯一id 'egsxlptzdq'
-      let self = this;
-      this.closePlv();
-      plv.init(optionsData).then(({ detail, chat }) => {
-        self.liveDetail = detail;
-
-        // 设置mode为live的videoOption
-        this.setLiveOption();
-        if (detail.isPPT) {
-          chat.on(chat.events.SLICESTART, () => {
-            // 开始直播
-          });
-        } else {
-          plv.api.getOrdinaryLiveStatus(detail.stream);
-        }
-      });
-    },
     openSetting(res) {
       console.log(res, 98);
     },
@@ -2659,8 +2611,7 @@ export default {
         resolve(waitUpload);
       });
     },
-    timeEvent() {
-      this.photoTime = this.refPlv.playCurrentTime();
+    timeEvent(playTime) {
       this.configPhoto();
       console.info(this.photoList, "photoList");
       let photoTime = 0; //获取拍照秒数
@@ -2668,7 +2619,7 @@ export default {
         photoTime = Number(this.photoList[i]); //获取拍照秒数
         if (
           (this.erJianErZao && !this.photoHistoryList.length) ||
-          (photoTime < this.playTime && photoTime > this.playTime - 8)
+          (photoTime < playTime && photoTime > playTime - 8)
         ) {
           //3秒区间内才触发拍照,避免拉动滚动条
           if (this.photoHistoryList.indexOf(i) < 0) {
@@ -2723,18 +2674,20 @@ export default {
         },
       }).then((res) => {});
     },
+    timeupdate(time) {
+      console.log("播放中", time);
+      this.clearPauseTimer();
+      if (this.playSecIsLearn && (this.erJianErZao || this.photoNum > 0)) {
+        this.isReach = false;
+        this.timeEvent(); 
+      }
+    },
     playing() {
       console.log("playing");
       if (this.noticeShow) {
         this.refPlv.playPause();
         return;
       }
-      this.timer && clearInterval(this.timer);
-      if (this.playSecIsLearn && (this.erJianErZao || this.photoNum > 0)) {
-        this.clearPauseTimer();
-        this.isReach = false;
-        this.timer = setInterval(this.timeEvent, 1000); //定时器
-      }
       this.studyLog();
       if (!this.recordObj.videoCurrentTime) {
         this.postStudyRecord(0);