Come ottenere la durata di un video in JS
Cosa ho imparato oggi: come ottenere la durata di un video in JS tramite il tag INPUT (type=”file”):
var duration = 0;
var fileInput = document.querySelector('input#video');
fileInput.addEventListener('change', function(e) {
window.URL = window.URL || window.webkitURL;
var el = document.createElement('video');
el.preload = 'metadata';
el.onloadedmetadata = function() {
duration = Math.round(el.duration * 1000);
window.URL.revokeObjectURL(this.src)
}
el.src = URL.createObjectURL(fileInput.files[0]);;
});




