Here the code:
var myVideos = [];
window.URL = window.URL || window.webkitURL;
document.getElementById('form__video-upload').onchange = setFileInfo;
function setFileInfo(){
var files = this.files;
myVideos.push(files[0]);
var video = document.createElement('video');
video.preload = 'metadata';
video.onloadedmetadata = function (){
window.URL.revokeObjectURL(video.src);
var duration = Math.floor(video.duration).toString();
myVideos[myVideos.length-1].duration = duration;
updateInfos();
}
video.src = URL.createObjectURL(files[0]);
}
function minTommss(minutes){
var sign = minutes < 0 ? "-":"";
var min = Math.floor(Math.abs(minutes));
var sec = Math.floor((Math.abs(minutes) * 60 ) % 60);
return sign + (min < 10 ? "0" : "") + (sec < 10 ? "0" : "") + sec;
}
function updateInfos(){
var infos = document.getElementById('infos');
for(var i = 0; i < myVideos.length; i++){
infos.value += myVideos[i].duration;
}
}
HTML PART:
<input type="file" id="form__video-upload">
I want to do something like when the input file video is selected the length of the video will display. The code I wrote gives me wrong video length.