HTML 5 Audio/Video获取播放进度

html

<video id="v1" src="http://0517.dev.victtech.com/ppt1/video/video1.mp4" controls></video>

js

<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script>
('document').ready(function(){
        var total_time =0;
        var record_flag = 0;
        //获取媒体总长度('#v1').bind('loadedmetadata',function(e){
            total_time = e.currentTarget.duration;
            console.log(total_time);
        });
        //获取当前播放长度
        $('#v1').bind('timeupdate',function(e){
            var ct = e.currentTarget.currentTime;
            if(ct>total_time*0.8 && record_flag==0){
                console.log('record');
                console.log(ct);
                record_flag =1;
            }

        });
    });
</script>

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注