Search code examples
htmlvideoprogresspreload

play html5 video after fully loaded


I am searching for a way to play an HTML video after it's fully loaded. I tried get a feedback when the video buffering is complete but it does't work. Here is my code :

var player = document.getElementById('bgvid');
player.addEventListener("progress", function() {
  console.log("1");
  if (player.buffered.length > 0) {
    console.log("2");
    var bufferedEnd = player.buffered.end(player.buffered.length - 1);
    var duration = player.duration;
    console.log(duration);
    if (duration > 0) {
      console.log((bufferedEnd / duration) * 100);
    }
  }
});

I get only "1" on the console so the buffer.length never pass zero even with the preload attribute on "auto". The only thing that makes any difference is the autoplay attribute. When is on i get the percent of buffer shown in console, but if i pause the video it stops again the buffering.

Thank you in advance for any ideas.


Solution

  • with the help of @Offbeatmammal i manage to solve my problem. The answer is here: Another: Force Chrome to fully buffer mp4 video. Thank everyone for your answers :D