请问视频卡顿这里的原理是怎样的?

来源:3-13 代码的优化

Nekosan

2018-03-18 21:05:46

在这段代码中:video.on("timeupdate", function(){});如果监听到video的timeupdate事件的发生,就会执行这个匿名函数function(){}。但是如果发生了卡顿,timeupdate事件没有发生,那么这个匿名函数function(){}就不会执行,而loading图片的代码块也在这个匿名函数里面,按道理说不是不会发生吗?

var loadingTimer = null;
    video.on("timeupdate", function() {
        var currentTime = video[0].currentTime;
        var duration = video[0].duration;
        var percent = 100 * currentTime / duration;
        $(".timeBar").css("width", percent + "%");
        $("#currentTime").html(timeFormat(currentTime));
        $(".loading").fadeOut(100);
        clearTimeout(loadingTimer);
        loadingTimer = setTimeOut(function() {
            if(!video[0].paused && !video[0].ended) {
                $(".loading").fadeIn(100);
            }
        }, 500)
    });


写回答

1回答

怎么都被占用了呢

2018-03-19

发生卡顿的时候,会出现loading图,不卡顿的时候,触发视频的timeupdate事件,执行函数内的 $(".loading").fadeOut(100);,loading图消失,是这么个过程。

0

0 学习 · 5012 问题

查看课程