我需要一种获取视频的总时间长度和使用jQuery的当前时间的方式,并以几个< div>标签。
<div id="current">0:00</div> <div id="duration">0:00</div>
解决方法
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); $("#duration").text(duration); }
笔记:
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