Fetches metadata for HTML5 videos.
function getVideoMeta(videoUrl, metaType, callback) {
var video = document.createElement('video');
video.preload = 'metadata';
video.src = videoUrl;
video.addEventListener('loadedmetadata', function() {
callback(null, video[metaType]);
});
video.addEventListener('error', function(error) {
callback(error, video);
});
}
getVideoMeta('http://video.webmfiles.org/big-buck-bunny_trailer.webm', 'duration', function(error, response){
if (error) {
console.log('Could not get video metadata.');
} else {
console.log('Video Duration: ' + response + ' seconds.');
}
});