html5视频的当前/持续时间? [英] current/duration time of html5 video?
问题描述
我需要一种方法来获取视频的总时间长度和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
这篇关于html5视频的当前/持续时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!