tanyanfei 4 years ago
parent
commit
0fa12475ec
2 changed files with 17 additions and 19 deletions
  1. 16 18
      pages/video/video.js
  2. 1 1
      pages/video/video.wxml

+ 16 - 18
pages/video/video.js

@@ -10,7 +10,7 @@ Page({
     title:'',
     url:'',
     time:0,
-    currentTime:0
+    duration:0
   },
 
   /**
@@ -26,27 +26,25 @@ Page({
       id:options.id
     })
   },
-  pause: function (event){
-    console.log(event)
+  end: function (event){
+    wx.request({
+      url: host + '/api/wx/savevtime',
+      method: 'post',
+      data: {
+        video_id: this.data.id,
+        time: this.data.duration
+      },
+      success: function (res) {
+
+      }
+    })
   },
   timeupdate: function (event){
-    console.log(event)
-    let cur = event.detail.currentTime
-    if (cur - this.data.currentTime>=10){
+    if (!this.data.duration){
         this.setData({
-          currentTime:cur
-        })
-        wx.request({
-          url: host+'/api/wx/savevtime',
-          method:'post',
-          data:{
-            video_id: this.data.id,
-            time: cur
-          },
-          success:function(res){
-
-          }
+          duration: event.detail.duration
         })
+        
     }
   },
   /**

+ 1 - 1
pages/video/video.wxml

@@ -1,2 +1,2 @@
-<video src='{{url}}' title="{{title}}" initial-time='{{time}}' bindtimeupdate='timeupdate' bindpause='pause'></video>
+<video src='{{url}}' title="{{title}}" initial-time='{{time}}' bindtimeupdate='timeupdate'  bindended='end'></video>
 <view>{{title}}</view>