2

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.

2 Answers2

0

You could use the canplaythrough event to check whether or not the the video had fully buffered (i.e: loaded).

I hope this is what you are looking for, good luck.

r3fresh_
  • 87
  • 1
  • 8
  • > "The canplaythrough event occurs when the browser estimates it can play through the specified audio/video without having to stop for buffering" – George Eleftheriou Jul 09 '16 at 22:33
  • thanks for the answer. this way the video is not fully loaded. also for some reason this event is triggered even without the preload attribute. I dont know why. All this on Chrome 51 – George Eleftheriou Jul 09 '16 at 22:35
0

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