使用@timeupdate获取视频长于和当前位置
onPlay(e) {
const wakit = e.detail.duration / 10;
const currentTime = e.detail.currentTime;
console.warn(wakit, currentTime);
for (let i = 1; i <= 10; i++) {
if (currentTime > (wakit * i) && currentTime < (wakit * i + 1)) {
console.log(`已到达${i * 10}%的位置`);
}
}
}
随机控制
const wakit = e.detail.duration / 100;
const currentTime = e.detail.currentTime;
console.warn(wakit, currentTime);
for (let i = 1; i <= 100; i++) {
if (currentTime > (wakit * i) && currentTime < (wakit * i + 1)) {
//下面的1就是控制百分比的
if (i % 1 === 0) {
console.log(`已到达${i}%的位置`);
}
}
}
每十秒执行一次
data() {
return {
lastCheckedTime: 0, // 上一次检查的时间
intervalId: null, // 定时器的ID
}
},
const currentTime = e.detail.currentTime; // 当前播放时间(秒)
const tenSecondInterval = 10; // 每10秒
if (currentTime - this.lastCheckedTime >= tenSecondInterval) {
this.lastCheckedTime = currentTime; // 更新上一次检查的时间
// 在这里执行你每10秒想要做的操作
console.log(`已播放 ${currentTime} 秒`);
// 如果你想要清除之前的定时器(例如,如果视频暂停或停止),可以在这里做
// clearInterval(this.intervalId);
}