Skip to content

Instantly share code, notes, and snippets.

@kodie
Last active August 5, 2016 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kodie/36f04f88a87263df7cc06ba116dfe288 to your computer and use it in GitHub Desktop.
Save kodie/36f04f88a87263df7cc06ba116dfe288 to your computer and use it in GitHub Desktop.
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.');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment