每个视频的视频百分比跟踪

时间:2016-05-05 01:16:51

标签: javascript jquery

我有两个HTML5视频。我想在视频启动时单独控制消息,并且分别在25%,50%和75%时控制消息。每个视频不应互相干扰。

这是我的代码:

var Html5Video = Html5Video || {};

(function() {

    function html5Play() {

        console.log("Completion rate: 0%");

        var duration = this.duration;
        var percent;

        this.addEventListener("timeupdate", function() {
            percent = Math.floor(this.currentTime / duration * 100).toFixed(2);

            if (Math.floor(percent) === 25) {
                console.log("Completion rate: 25%");
            }

            if (Math.floor(percent) === 50) {
                console.log("Completion rate: 50%");
            }

            if (Math.floor(percent) === 75) {
                console.log("Completion rate: 75%");
            }
        });

        this.addEventListener("ended", function() {
            console.log("Completion rate: 100%");
        });
    }

    Html5Video.Video = function() {
        var videos = document.getElementsByTagName("video");

        for (var i = 0; i < videos.length; i++) {
            videos[i].addEventListener("play", html5Play);
        }
    }

})();

$(function() {
    Html5Video.Video();
});

非常感谢任何帮助。

0 个答案:

没有答案