<video id="myVideo" ref="myVideo"
poster="/static/images/videoPoster.png"
@timeupdate="timeupdate"
:duration="duration"
:current="currentTime"
:src="localVideoPath"
:advanced="advanced"
object-fit="fill"
controls="true"
show-play-btn="true"
show-center-play-btn="true"
show-loading="true">
</video>
设置advanced
data() {
return {
//seek生效的关键代码
advanced: [
{
"key": "enable-accurate-seek",
"value": 1,
"type": "player",
}
]
currentTime: 0,
videoUrl: '',
localVideoPath: '',
}
}
onload 方法
需要设置好video的src路径后再创建 uni.createVideoContext
onLoad(e){
//这里是先下载到本地,然后再播放的
let localVideoPath = uni.getStorageSync(this.videoUrl);
//网络地址可以正常跳转但是本地地址不行,设置之后就正常了
this.localVideoPath = plus.io.convertLocalFileSystemURL(localVideoPath)
this.$nextTick(() => {
this.videoContext = uni.createVideoContext('myVideo',this)
this.videoHeight = 450;
})
this.$forceUpdate()
},
seek 需要整型
seek(time) {
let currentTime = parseInt(time);
this.currentTime = currentTime;
this.videoContext.seek(currentTime);
console.info("seek",currentTime)
setTimeout(() => {
this.videoContext.play();
}, 200);
}