UNIAPP视频获取每个10%的位置

使用@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);  
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值