HTML5 Game - Get Buffered media

Introduction

We can get a TimeRanges object for the portions of the file that have buffered.

Demo

ResultView the demo in separate window

<!DOCTYPE html>
<html>
  <body>
    <audio controls>
        <source src='http://java2s.com/style/demo/your.ogg' type='audio/ogg; codecs=vorbis'>
         <source src='http://java2s.com/style/demo/your.mp3' type='audio/mpeg'>
    </audio>
    <script>
      let ele = document.querySelector('audio');
      //if you have a video tag
      // let ele = document.querySelector('video'); 
function log()  {/*www.  jav  a  2 s.  c o  m*/
  for (let i = 0; i < ele.buffered.length; i++)
  {
    console.log("Portion " + i);
    console.log("  Start: " + ele.buffered.start(i)); 
    console.log("  End: " + ele.buffered.end(i));
  }
}
      </script>
  </body>
</html>

Related Topic