Przeglądaj źródła

官方作品点击【去朗读】视频进来自动播放-点击【开始朗读】-321倒计时

bayi 2 lat temu
rodzic
commit
9668f3871d
3 zmienionych plików z 50 dodań i 36 usunięć
  1. 4 2
      components/videoPreview/index.js
  2. 1 1
      pages/match/index.js
  3. 45 33
      pages/reading/index.js

+ 4 - 2
components/videoPreview/index.js

@@ -268,11 +268,13 @@ Component({
       let videoType = this.properties.videoType
       let url = ''
       if (!this.data.isOfficial || this.data.selfUid == videoInfo.user.uid) {
-        url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}`
+        // autoPlay自动播放
+        url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}&autoPlay=true`
       } else if (videoType == 'public' || videoType == 'follow') {
         url = `/pages/pkPage/index?videoId=${readId}`
       } else if (videoType == 'pk') {
-        url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}&readingType=${videoType}`
+        // voluntarily自动录制
+        url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}&readingType=${videoType}&voluntarily=true`
       } else {
         url = `/pages/reading/index?videoId=${videoInfo.userRead.exampleId}`
       }

+ 1 - 1
pages/match/index.js

@@ -91,7 +91,7 @@ Page({
     target
   }) {
     wx.navigateTo({
-      url: `/pages/reading/index?videoId=${target.dataset.id}&readingType=readMatch`
+      url: `/pages/reading/index?videoId=${target.dataset.id}&readingType=readMatch&autoPlay=true`
     })
   },
   jumpUserInfo({

+ 45 - 33
pages/reading/index.js

@@ -66,8 +66,16 @@ Page({
     }
   },
   onLoad(options) {
+    console.log(options);
     let videoId = options.videoId
-    this.getreadInfo(videoId, options.reset)
+    this.getreadInfo(videoId, options.reset).then(res => {
+      if (options.voluntarily) {
+        this.setCountDown()
+      }
+      if (options.autoPlay) {
+        this.videoPlay()
+      }
+    })
     this.setData({
       readingReset: options.reset || false,
       readingType: options.readingType || 'public',
@@ -151,40 +159,44 @@ Page({
         ["silderData.sliderValue"]: 100
       })
     })
+
   },
   // 获取阅读内容
-  async getreadInfo(videoId, reset = false) {
-    let videoInfo = await getreadInfo(videoId)
-    /*  wx.setNavigationBarTitle({
-       title: videoInfo.userRead.title
-     }) */
-    let data = JSON.parse(videoInfo.userReadExtend.lessonText)
-    data = data.map((item, index) => {
-      item.time = Number(item.time)
-      item.readTime = data[index + 1] ? data[index + 1].time - item.time : ''
-      return item
-    })
-    this.setData({
-      videoPath: videoInfo.userRead.originVideo,
-      article: data,
-      videoInfo,
-      ["silderData.endTime"]: setDuration(videoInfo.userRead.duration)
-    })
-    if (!reset) {
-      this.getHeight()
-    }
-    if (this.data.videoInfo.userReadExtend.resourcesType == 0) {
-      this.videoContext = wx.createVideoContext('myVideo')
-    } else {
-      this.innerAudioContext.src = videoInfo.userRead.originVideo
-      this.innerAudioContext.onEnded(res => {
-        console.log("138innerAudioContext触发的");
-        this.resetReading()
+  getreadInfo(videoId, reset = false) {
+    return new Promise(async (resolve, reject) => {
+      let videoInfo = await getreadInfo(videoId)
+      /*  wx.setNavigationBarTitle({
+         title: videoInfo.userRead.title
+       }) */
+      let data = JSON.parse(videoInfo.userReadExtend.lessonText)
+      data = data.map((item, index) => {
+        item.time = Number(item.time)
+        item.readTime = data[index + 1] ? data[index + 1].time - item.time : ''
+        return item
       })
-      this.innerAudioContext.onStop((res) => {
-        console.log("143innerAudioContext触发的");
-      });
-    }
+      this.setData({
+        videoPath: videoInfo.userRead.originVideo,
+        article: data,
+        videoInfo,
+        ["silderData.endTime"]: setDuration(videoInfo.userRead.duration)
+      })
+      if (!reset) {
+        this.getHeight()
+      }
+      if (this.data.videoInfo.userReadExtend.resourcesType == 0) {
+        this.videoContext = wx.createVideoContext('myVideo')
+      } else {
+        this.innerAudioContext.src = videoInfo.userRead.originVideo
+        this.innerAudioContext.onEnded(res => {
+          console.log("138innerAudioContext触发的");
+          this.resetReading()
+        })
+        this.innerAudioContext.onStop((res) => {
+          console.log("143innerAudioContext触发的");
+        });
+      }
+      resolve()
+    })
   },
   // 开始录制
   setCountDown() {
@@ -666,7 +678,7 @@ Page({
                         }
                       }
                       setTimeout(() => {
-                        console.log(wx.getStorageSync('shareVideoId'),'reading-wx.getStorageSync');
+                        console.log(wx.getStorageSync('shareVideoId'), 'reading-wx.getStorageSync');
                         wx.canvasToTempFilePath({
                           canvas: canvas,
                           success(res) {