<template>
<view>
<video id="videoPlayer" :src="videoSrc" controls="false" autoplay="true"
@timeupdate="onVideoTimeUpdate"></video>
<view class="btn-landscape" @tap="seek()">seek</view>
<view class="btn-landscape" @tap="changeVideo()">切换</view>
</view>
</template>
<script>
export default {
data() {
return {
videoCtx:null,
videoIdx: 0,
videoList:[
"http://coolanimals.info/upload/video/life_01.mp4",
"http://coolanimals.info/upload/video/life_02.mp4"
]
}
},
computed :{
videoSrc:function(){
return this.videoList[this.videoIdx];
}
},
onLoad() {
this.videoCtx = uni.createVideoContext("videoPlayer", this);
},
methods: {
seek() {
this.videoCtx.seek(100);
},
changeVideo(){
let newIdx = this.videoIdx+1;
if(newIdx>=this.videoList.length){
this.videoIdx = 0;
}else{
this.videoIdx = newIdx;
}
},
onVideoTimeUpdate(e){
console.log("====onVideoTimeUpdate===",e.detail);
}
}
}
</script>
<style>
.btn-landscape {
width: 200px;
height: 40px;
background-color: #CCCCCC;
color: #FFFFFF;
border-radius: 20px;
line-height: 40px;
text-align: center;
margin: 10px auto;
font-weight: 900;
font-size: 16px;
}
</style>
爱吃鱼的靖哥哥 (作者)
多谢了,我现在每次切换都调用下seek(0)来规避问题了
2020-05-27 08:48