当前位置:   article > 正文

微信小程序视频只能播放一个_微信小程序video标签设置视频自动播放只自动播放第一个

微信小程序video标签设置视频自动播放只自动播放第一个

1.给视频一个点击事件(定义一个ID传过去)

  1. <video src='{{item.fileUrl}}' data-index="{{index}}" id="{{index}}"
  2. bindtap="video_play" show-fullscreen-btn='{{false}}'>
  3. </video>

2.在JS里面写点击事件方法

  1. data: {
  2. indexCurrent:null,
  3. },
  4. // 点击cover播放,其它视频结束
  5. video_play(e) {
  6. var curIdx = e.currentTarget.id;
  7. // 没有播放时播放视频
  8. if (!this.data.indexCurrent) {
  9. this.setData({
  10. indexCurrent: curIdx
  11. })
  12. var videoContext = wx.createVideoContext(curIdx,this) //这里对应的视频id
  13. videoContext.play()
  14. } else {
  15. // 有播放时先将prev暂停,再播放当前点击的current
  16. var videoContextPrev = wx.createVideoContext(this.data.indexCurrent,this)
  17. //this是在自定义组件下,当前组件实例的this,以操作组件内 video 组件
  18. if (this.data.indexCurrent != curIdx) {
  19. videoContextPrev.pause()
  20. this.setData({
  21. indexCurrent: curIdx
  22. })
  23. var videoContextCurrent = wx.createVideoContext(curIdx,this)
  24. videoContextCurrent.play()
  25. }
  26. }
  27. },

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/468832
推荐阅读
相关标签
  

闽ICP备14008679号