同一个页面,多个video组件,点击播放后,所有视频都同时播放。如何实现点击播放一个视频,自动停止播放其他视频?
网友回复:
<video id="video1" data-id="1" src="https://b.mp4" bindplay="StartPlay"></video>
<video id="video2" data-id="2" src="https://a.mp4" bindplay="StartPlay"></video>
StartPlay:function(e){
console.log(e)
var ind = e.currentTarget.dataset.id
if(ind=="1"){
var v="video"+"2"
//this.videoContext = wx.createVideoContext('video2')
}else{
var v = "video" + "1"
//this.videoContext = wx.createVideoContext('video1')
}
this.videoContext = wx.createVideoContext(v)
this.videoContext.pause()
}