收藏
回答

视频列表多个视频无法控制只有一个视频处于播放状态?

<video style="width:690rpx" id="myVideo{{idx}}"
          poster="{{ossUrl+listItem.url+'?x-oss-process=video/snapshot,t_100,m_fast'}}" src="{{ossUrl+listItem.url}}"
          binderror="videoErrorCallback" object-fit="contain" show-play-btn="{{true}}" controls data-index='{{idx}}'
          bindtap="videoPlay"></video>


//js
videoPlay: function (e) {
    var that = this;
    var curIdx = e.currentTarget.dataset.index;
    // 有播放时先将prev暂停,再播放当前点击的current
    if (that.data.indexCurrent != null) {
      console.log('aa')
      var videoContextPrev = wx.createVideoContext('myVideo' + that.data.indexCurrent)
      if (that.data.indexCurrent != curIdx) {
        console.log('cc')
        videoContextPrev.pause()
      }
      that.setData({
        indexCurrent: curIdx
      })
      var videoContextCurrent = wx.createVideoContext('myVideo' + curIdx)
      videoContextCurrent.play()
      if(curIdx ==that.data.indexCurrent ){
        videoContextPrev.pause()
  
      }
    } else {  // 没有播放时播放视频
      console.log('bb')
      that.setData({
        indexCurrent: curIdx
      })
      var videoContext = wx.createVideoContext('myVideo' + curIdx) //这里对应的视频id
      videoContext.play()
    }
  },

网上找了很多个方法,在我这里都不行,上面写法有啥问题吗?
回答关注问题邀请回答
收藏
登录 后发表内容
问题标签