前端获取视频id,使用pause(),play()方法控制视频播放和暂停。
1、前端代码:
<template> <view class="video"> <video id="videoId" :src="detail.resDetail.playUrl" autoplay='true' enable-play-gesture='true' controls='true' objectFit="cover" @fullscreenchange='fullscreenchange' play-strategy='2'></video> </view> <view @tap="play" v-if="isPlaying"> <image src="../../static/pasue.png" mode="widthFix"></image> <text>暂停</text> </view> <view @tap="play" v-if="!isPlaying"> <image src="../../static/play.png" mode="widthFix"></image> <text>播放</text> </view> </template>
2、js代码:
<script>
export default {
// 播放,暂停
play(){
let videoContext = uni.createVideoContext('videoId', this)
if (this.isPlaying) {
videoContext.pause();
} else {
videoContext.play();
}
this.isPlaying = !this.isPlaying;
},
}
</script>
关于简忆
简忆诞生的故事



粤ICP备16092285号
文章评论(0)