I want to play a video of about 30 seconds on my website that uses html5 css and javascript. What I would like is to make sure the video is loaded before playing so it plays with out interruptions.
Any quick and simple solutions.
I want to play a video of about 30 seconds on my website that uses html5 css and javascript. What I would like is to make sure the video is loaded before playing so it plays with out interruptions.
Any quick and simple solutions.
You'll need to implement javascript to achieve what you're looking for.
You can bind the "buffered" event, but (in Chrome at least) this works fine except that it doesn't call the last "buffered" event (i.e. it will detect 90%...94%...98%... but won't call on 100%).
Note: recent versions of jQuery should use .prop()
instead of .attr()
To get around this I've used setInterval() to check the buffer every 500ms (where $html5Video is your <video>
element:
var videoDuration = $html5Video.attr('duration');
var updateProgressBar = function(){
if ($html5Video.attr('readyState')) {
var buffered = $html5Video.attr("buffered").end(0);
var percent = 100 * buffered / videoDuration;
//Your code here
//If finished buffering buffering quit calling it
if (buffered >= videoDuration) {
clearInterval(this.watchBuffer);
}
}
};
var watchBuffer = setInterval(updateProgressBar, 500);