current/duration time of html5 video?

前端 未结 5 1008
青春惊慌失措
青春惊慌失措 2020-11-28 07:23

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

tags.

5条回答
  •  庸人自扰
    2020-11-28 08:02

    HTML:

    
    
    0:00
    0:00

    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

提交回复
热议问题