Skip to content

Instantly share code, notes, and snippets.

@chrisallick
Created September 6, 2012 00:01
Show Gist options
  • Save chrisallick/3648196 to your computer and use it in GitHub Desktop.
Save chrisallick/3648196 to your computer and use it in GitHub Desktop.
faster prebuffer of scrubbing
function addSourceToVideo(element, src, type) {
var source = document.createElement('source');
source.src = src;
source.type = type;
element.appendChild(source);
}
var video;
var index = 0;
$(document).ready(function(){
video = document.getElementsByTagName('video')[0];
addSourceToVideo( video, "http://video-js.zencoder.com/oceans-clip.ogv", "video/ogv");
addSourceToVideo( video, "http://video-js.zencoder.com/oceans-clip.mp4", "video/mp4");
video.addEventListener("progress", progressHandler,false);
bindKeys();
});
progressHandler = function(e) {
if( video.duration ) {
var percent = video.buffered.end(0) / video.duration;
console.log( percent );
if( percent >= 1 ) {
console.log("loaded!");
}
video.currentTime = video.duration * percent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment