微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我需要一种获取视频的总时间长度和使用jQuery的当前时间的方式,并以几个< div>标签
<div id="current">0:00</div>
<div id="duration">0:00</div>

我一直在搜索,我知道如何让他们,我不能显示它们。 #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);
    $("#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

原文地址:https://www.jb51.cc/jquery/183538.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐