Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
158
rated 0 times [  159] [ 1]  / answers: 1 / hits: 42716  / 12 Years ago, thu, march 8, 2012, 12:00:00

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))

More From » jquery

 Answers
9

canplaythrough is the event that should fire when enough data has downloaded to play without buffering.


From the Opera teams excellent (although maybe very slightly dated now) resource Everything you need to know about HTML5 video and audio



If the load is successful, whether using the src attribute or using source elements, then as data is being downloaded, progress events are fired. When enough data has been loaded to determine the video's dimensions and duration, a loadedmetadata event is fired. When enough data has been loaded to render a frame, the loadeddata event is fired. When enugh data has been loaded to be able to play a little bit of the video, a canplay event is fired. When the browser determines that it can play through the whole video without stopping for downloading more data, a canplaythrough event is fired; this is also when the video starts playing if it has a autoplay attribute.



'canplaythrough' support matrix available here: https://caniuse.com/mdn-api_htmlmediaelement_canplaythrough_event


You can get around the support limitations by binding the load element to the same function, as it will trigger on those.


[#86988] Wednesday, March 7, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
shaina

Total Points: 161
Total Questions: 99
Total Answers: 108

Location: American Samoa
Member since Fri, Sep 24, 2021
3 Years ago
;