html5视频的当前/持续时间?

html5视频的当前/持续时间?

问题描述:

我需要一种方法来获取视频的总时间长度和jquery的当前时间,并将其显示在几个< div>中。标签。

I need a way of getting the total time length of the video and the current time with jquery and displaying it in a couple of <div> tags.

<div id="current">0:00</div>
<div id="duration">0:00</div>

我一整天都在搜索,我知道如何获取它们,但我无法显示它们。 #jquerynoob

I've been searching all day and I know how to get them I just can't display them. #jquerynoob

HTML:

<video
    id="video-active"
    class="video-active"
    width="640"
    height="390"
    controls="controls">
    <source src="myvideo.mp4" type="video/mp4">
</video>
<div id="current">0:00</div>
<div id="duration">0:00</div>

JavaScript:

JavaScript:

$(document).ready(function(){
  $("#video-active").on(
    "timeupdate", 
    function(event){
      onTrackedVideoFrame(this.currentTime, this.duration);
    });
});

function onTrackedVideoFrame(currentTime, duration){
    $("#current").text(currentTime); //Change #current to currentTime
    $("#duration").text(duration)
}

注意:


每15到250毫秒,或每当MediaController的媒体控制器
位置更改,以最少的时间发生,用户代理必须
排队任务以在
MediaController上触发名为timeupdate的简单事件。

Every 15 to 250ms, or whenever the MediaController's media controller position changes, whichever happens least often, the user agent must queue a task to fire a simple event named timeupdate at the MediaController.

http://www.w3.org/TR/html5/embedded-content-0.html#media-controller-position