html5开发<video>视频字幕的程序

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>使用video实现实时字幕的效果</title>
    <style>
        #box{
            border: 1px solid red;
            width: 400px;
            height: 400px;
            position: absolute;
        }
        video{
            position: relative;
        }
        #caption{
            position: relative;
            left: 180px;
            top: -60px;
            font-size: 18px;
            font-weight: bold;
        }
    </style>
    <script src="js/jquery.js"></script>
    <script>
        window.addEventListener("load",function(){
            //我们的数据数组
            var captionData=[];
            //首先获得我们的视频对象
            var myvideo=document.getElementByIdx_x("myvideo");
            //此项表示加载之后执行以下的操作
            //获得我们存放字幕的地方
            var mycaption=document.getElementByIdx_x("caption");
            //读入我们的字幕数据
            $.get("js/captions.js",function(text,status){
                captionData=eval_r(text);
            });
 
           
            window.addEventListener("timeupdate",function(){
                var csec=myvideo.currentTime;
                //开始进行判断
                for(var i=0;i<captionData.length;i++){
                    //根据当前播放的时间跟我们json的时间进行比较
                    if(csec>captionData[i].start&&csec<captionData[i].end){
                         //此时将字幕设置
                        mycaption.innerHTML=captionData[i].text;
                        mycaption.style.color=captionData[i].color||"#ff0";
                    }
                }
 
            },true);
 
        },true);
 
 
 
 
 
    </script>
</head>
<body>
    <div id="box">
        <video controls width="400" id="myvideo">
            <source src="video/first.mp4">
        </video>
        <div id="caption">播放开始</div>
    </div>
</body>
</html>

html5开发<video>视频字幕的程序,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。