0

视频正在运行,带有 setInterval 的其他函数运行良好,除了 video.getCurrentTime() 根本不显示在 div id = "test" 中。我希望每次视频运行时都显示视频时间。我不知道为什么。这是我的示例代码,

<html>
<head>
<script>
setInterval(function(){

                    var t = document.getElementById('test');

                    video = document.getElementById('caption');

                    t.innerHTML = video.getCurrentTime();


            },1000);
</script>
</head>

    <body>

        <div>
            <video id="caption" width="320" height="240" controls>
                <source src="caption.mp4" type="video/mp4">
            </video> 
        </div>
        <div id="container">
        </div>
        <div id ="timer">
        </div>
        <div id = "test">   
        </div>
    </body>
</html>
4

2 回答 2

1

这是一个工作版本:

<html>
<head>
</head>

<body>

    <div>
        <video id="caption" width="320" height="240" controls="">
            <source src="caption.mp4" type="video/mp4">
        </video> 
    </div>
    <div id="container">
    </div>
    <div id ="timer">
    </div>
    <div id="test">Hello   
    </div>
    <script>
        function displayTime(){
            var time = document.getElementById('test');

            var video = document.getElementById('caption');

            //time.innerHTML = video.currentTime;

            var text = "", cap = "";

                for( int i = 0; i < subtitleArray.length;i++)
                {
                    //var currentTime = video.currentTime();
                    var cueStart = parseFloat(subtitleArray[i][0]);
                    var cueEnd = cueStart + parseFloat(subtitleArray[i][1]);
                    //var diff = cueStart - currentTime;

                    cap = subtitleArray[i][2];

                    if (video.currentTime >= cueStart && video.currentTime <= cueEnd) {
                       text = cap.text;   
                    }
                }

                t.innerHTML = text; 
        }
        setInterval(displayTime,1000);
</script>
    </body>
</html>
于 2013-03-20T16:05:47.113 回答
0

我认为这将是 video.currentTime,而不是 getCurrentTime,最好将脚本标记放在正文末尾,或者您可以执行 $(document).ready(function(){ }); 在jQuery中

于 2013-03-20T15:46:27.873 回答