How I can get video duration
freelanceromarr opened this issue · 1 comments
freelanceromarr commented
When I upload upload video, I need video duration, How I can get it
Kendysond commented
Hi @freelanceromarr ,
here's what I use, I don't know if it will help.
I have a method for the @select
event, and in that function, I try to use HTML to open the video file and get the metadata.
I think it works everytime so far.
<vue-file-agent ref="fileUpload"
@select="filesSelected($event)" />
setFileInfo(file) {
let myVideos = [ file.file ];
var video = document.createElement('video');
video.preload = 'metadata';
video.onloadedmetadata = function() {
window.URL.revokeObjectURL(video.src);
var duration = video.duration;
file.duration = duration;
}
video.src = URL.createObjectURL(file.file);
},
async filesSelected(fileRecordsNewlySelected) {
var validFileRecords = fileRecordsNewlySelected.filter((fileRecord) => !fileRecord.error);
for (let index = 0; index < validFileRecords.length; index++) {
const validFile = validFileRecords[index];
const fileName = validFile.name()
this.setFileInfo(validFile)
}