小程序获取当前播放长度和视频总长度,可在播放到某一时长暂停或停止视频

  methods: {
    // 视频时长更新
    timeupdate(e){
      console.log(e)
      let duration = e.detail.duration
      let currentTime = e.detail.currentTime
      console.log(duration)
      console.log(currentTime)
      if (currentTime > duration - 2.925){ 
         // 停止视频
        wx.createVideoContext(this.data.indexCurrent, this).stop()
         // 暂停视频
        // wx.createVideoContext(this.data.indexCurrent, this).pause()
        console.log("可以暂停了")
      }
    }
  }

wxml

<video bindtimeupdate="timeupdate" bindtap="video_play" id="{{item.sid}}" poster="{{item.thumbnail}}" auto-pause-if-open-native wx:elif="{{item.type=='video'}}" src="{{item.images}}" src="{{item.video}}"></video>
原文地址:https://www.cnblogs.com/zwnsyw/p/12536015.html