html5 display audio currentTime

前端 未结 9 914
生来不讨喜
生来不讨喜 2020-11-28 05:29

I would like to display the current time of of an html 5 audio element and the duration of that element. I\'ve been looking over the internet but can\'t find a functional sc

9条回答
  •  难免孤独
    2020-11-28 06:22

    robertc's version will work fine except for the fact that it does not turn the number of seconds you get from math.floor() into proper time values.

    Here is my function called when ontimeupdate is called:

    
    
    

    I modified formatSecondsAsTime() from something I found here:

    function formatSecondsAsTime(secs, format) {
      var hr  = Math.floor(secs / 3600);
      var min = Math.floor((secs - (hr * 3600))/60);
      var sec = Math.floor(secs - (hr * 3600) -  (min * 60));
    
      if (min < 10){ 
        min = "0" + min; 
      }
      if (sec < 10){ 
        sec  = "0" + sec;
      }
    
      return min + ':' + sec;
    }
    

提交回复
热议问题