微信小程序解决多个视频播放的问题

效果图:

这里写图片描述

本例子:是图片和多个视频混在一起

  • html
<view class="case-ul">
      <repeat for="{{list}}" index="index" item="item" key="key">
        <view class="case-li case-view-item">
          <image hidden="{{item.isPlaying}}" style="" class="case-picture" src="{{item.path_url}}" mode="scaleToFill"></image>
          <!-- 是视频 -->
          <video wx:if="{{item.isPlaying}}" id="video-{{index}}" class="video" src="{{item.video_url}}" controls></video>
          <image wx:if="{{item.type==1}}" hidden="{{item.isPlaying}}" class="bt" mode="scaleToFill" @tap="playVideo({{item}},{{index}})" src="./images/play-bt.png"></image>  <!--前提一个播放的按钮-->
        </view>
      </repeat>
    </view>
  1. list是一个数组
  2. type 后台给我一个标识,0:图片 。 1:视频
  3. isPlaying 前台自己添加是否播放视频
  4. path_url 图片的地址。视屏也会反一个封面截图,字段都是path_url

    • js
playVideo(item, index) {
  this.list.forEach(n => {
    n.isPlaying = false;
  })
  this.list[index].isPlaying = true;
  let videoContext = wx.createVideoContext(`video-${index}`)
  videoContext.play()
},
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值