小程序视频多个视频播放与暂停
先看效果:
这里就不贴全部代码了。
wxml
<view class="pvideo" wx:if="{{item.video}}"> <video src="{{item.video}}" controls id='video{{index}}' data-index="{{index}}" bindplay="videoPlay"></video> </view>
js
data{
videoIndex:0,
},
videoPlay : function(e){ var index = e.currentTarget.dataset['index']; //停止正在播放的视频 if (index != this.data.videoIndex){ var videoContextPrev = wx.createVideoContext('video' + this.data.videoIndex) videoContextPrev.stop() } //将点击视频进行播放 this.setData({ videoIndex: index }) setTimeout(function () { var videoContext = wx.createVideoContext('video' + index) videoContext.play() },200); },
(转载请注明花儿为何那样红博客)