Last active
August 5, 2016 21:30
-
-
Save kodie/36f04f88a87263df7cc06ba116dfe288 to your computer and use it in GitHub Desktop.
Fetches metadata for HTML5 videos.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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