微信小程序限制同时播放多个视频

在这里插入图片描述

<view class="box">
	<view
	 class="row"
	 wx:for="{
     
     {videoList}}"
	 wx:key="index"
	>
		<view class="cover">
			<video
			 src="{
     
     {item.url}}"
			 id="{
     
     {item.id}}"
			 bindplay="playVideo"
			></video>
		</view>
	</view>
</view>
Page({
    
    
  data: {
    
    
    videoList: [{
    
    
      id: 1,
      url: "https://video.pearvideo.com/mp4/adshort/20210329/cont-1724872-15642559_adpkg-ad_hd.mp4"
    }, {
    
    
      id: 2,
      url: "https://video.pearvideo.com/mp4/adshort/20210329/cont-1724872-15642559_adpkg-ad_hd.mp4"
    }, {
    
    
      id: 3,
      url: "https://video.pearvideo.com/mp4/adshort/20210329/cont-1724872-15642559_adpkg-ad_hd.mp4"
    }]
  },
  playVideo(e) {
    
    
    let id = e.currentTarget.id
    this.id !== id && this.videoContext && this.videoContext.stop();
    this.id = id;
    this.videoContext = wx.createVideoContext(id)
  }
})

猜你喜欢

转载自blog.csdn.net/AK852369/article/details/115317590