html5 视频的当前/持续时间? [英] current/duration time of html5 video?
问题描述
我需要一种使用 jquery 获取视频总时长和当前时间并将其显示在几个 <div> 中的方法.标签.
0:00<div id="持续时间">0:00</div>
我已经搜索了一整天,我知道如何获取它们,但我无法显示它们.#jquerynoob
HTML:
<source src="myvideo.mp4" type="video/mp4"></视频><div id="当前">0:00</div><div id="持续时间">0:00</div>
JavaScript:
$(document).ready(function(){$("#video-active").on("时间更新",功能(事件){onTrackedVideoFrame(this.currentTime, this.duration);});});功能 onTrackedVideoFrame(当前时间,持续时间){$("#current").text(currentTime);//改变#current到currentTime$("#duration").text(duration)}
注意事项:
<块引用>每 15 到 250 毫秒,或每当 MediaController 的媒体控制器位置发生变化,以发生频率最低的为准,用户代理必须将任务排队以触发名为 timeupdate 的简单事件媒体控制器.
http://www.w3.org/TR/html5/embedded-content-0.html#media-controller-position
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>
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:
$(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)
}
Notes:
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屋!