uniapp-H5视频从上次断开位置开始播放
<video
:src="video.sourceVideoUrl"
:poster="video.coverUrl"
controls
@timeupdate="timeupdate"
id="demoVideo"
>
</video>
<script>
methods: {
isAndroid(){
var u = navigator.userAgent;
if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1){
return true;
}
},
timeupdate(e){
this.currentTime = Math.floor(e.detail.currentTime);
this.currentTimeObj[this.ID] = this.currentTime;
if(e.detail.currentTime === e.detail.duration){
this.currentTimeObj[this.ID] = 0;
}
uni.setStorageSync("currentTimeObj", JSON.stringify(this.currentTimeObj));
},
getVideo(){
this.$nextTick(() => {
console.log('上次断开时间:',this.currentTime)
let videoDom = document.querySelector('#demoVideo video');
if(this.isAndroid()){
videoDom.currentTime = this.currentTime;
}else{
videoDom.addEventListener('canplay',() => {
videoDom.currentTime = this.currentTime;
});
}
})
}
},
onLoad(option) {
if(uni.getStorageSync("currentTimeObj")){
this.currentTimeObj = JSON.parse(uni.getStorageSync("currentTimeObj")) || {};
this.currentTime = this.currentTimeObj[this.ID];
console.log(this.currentTime)
}
},
</script>