HTML5 Game - Get Played media

Introduction

To know which parts of the media have been played.

Played is a property that can be used with JavaScript to get a TimeRanges object.

It has the start and end times of each portion of the track that has been played.

Demo

ResultView the demo in separate window

<!DOCTYPE html>
<html>

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

Related Topic