Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 video full preload in javascript

I have a high quality video which I cannot compress too much as it's going to be the base of a lot of image analysis whereby each frame will be redrawn into the canvas and then manipulated.

I'm trying to preload the whole thing before playing it as I can't have the video stop, buffer and continue. Is there an event which I can listen for which signifies that the whole video has preloaded before I commence playback?

Here's how I'm doing it in JS/jQuery:

this.canvas            = this.el.find("canvas")[0];
this.video             = this.el.find("video")[0];
this.ctx               = this.canvas.getContext("2d");
this.video.autoplay    = false;

this.video.addEventListener("play",this.draw)
this.video.addEventListener("timeupdate",this.draw)
this.video.addeventlistener("ended",this.trigger("complete",this))
like image 863
Alex Avatar asked Mar 08 '12 10:03

Alex


People also ask

What is preload in HTML video?

The preload attribute specifies if and how the author thinks that the video should be loaded when the page loads. The preload attribute allows the author to provide a hint to the browser about what he/she thinks will lead to the best user experience. This attribute may be ignored in some instances.

What is preload tag in HTML?

The HTML preload Attribute is used to specify the way the author thinks the media should be loaded when the page loads. The preload attribute allows the author to portray to the browser about the way the user experience of a website should be implemented.

Which are the correct values for preload attribute of video tag?

The html video element's preload attribute can have three values: metadata , auto , or none .


1 Answers

This will load the entire video in JavaScript

var r = new XMLHttpRequest();
r.onload = function() {
    myVid.src = URL.createObjectURL(r.response);
    myVid.play();
};
if (myVid.canPlayType('video/mp4;codecs="avc1.42E01E, mp4a.40.2"')) {
    r.open("GET", "slide.mp4");
}
else {
    r.open("GET", "slide.webm");
}

r.responseType = "blob";
r.send();
like image 101
jacobsgriffith Avatar answered Sep 19 '22 11:09

jacobsgriffith