<image src="/images/play_.png" bindtap='videoTap' wx:if='{{isPause}}' class="img_"></image>
<video class="video" id="myVideo" src="{{videoUrl}}" autoplay="{{player.autoplay}}" controls="{{false}}" loop="player.loop" show-fullscreen-btn='{{controls}}' object-fit='cover' bindtap='videoTap' bindtimeupdate="timeupdate"></video>
一定要给视频绑定一个id
.img_{
width: 130rpx;
height: 130rpx;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
z-index: 2;
}
data:{
// 播放器参数
player: {
autoplay: true,
controls: false,
loop: true
},
// 控制视频的播放
play:false,
// 视频暂停图片的显示
isPause:false
},
// 视频按钮
videoTap(){
//获取video
this.videoContext = wx.createVideoContext('myVideo')
console.log(this.videoContext)
if (this.data.play){
//开始播放
this.videoContext.play()
this.setData({
play:false,
isPause:false
})
}else{
//暂停播放
this.videoContext.pause()
this.setData({
play: true,
isPause: true
})
}
},
VideoContext.play()
播放视频
VideoContext.stop()
停止视频---从头播放
VideoContext.pause()
暂停视频---继续播放