需要记录视频的播放进度,重新进入时回到退出前的位置,并继续播放
但是ios直接赋值currentTime无效,原因就是判断资源可播放时(canplay)再设置才可以,所以要根据不同系统判断一下,上代码
// 判断是否安卓设备
isAndroid() {
const u = navigator.userAgent;
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {
return true;
}
return false;
},
// 设置播放时间
initPlayer() {
const videoRef = this.$refs.video;
if (this.isAndroid()) {
videoRef.currentTime = this.options.currentTime ?? 0;
} else {
videoRef.addEventListener('canplay', () => {
try {
if (videoRef.currentTime === 0) {
videoRef.currentTime = this.options.currentTime ?? 0;
}
} catch (error) {
console.warn('@VideoRef: set currentTime', error);
}
});
}
}