I'm trying to get video duration, I can get in in console but I can't reach it and store in DB or even alert it, if I tried to console it in this way file.duration i get undefined please advice
setFileInfo(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);
}
CodePudding user response:
all you need just to patch result of the video duration inside setFileInfo function
setFileInfo(file) {
var video = document.createElement('video');
video.preload = 'metadata';
video.onloadedmetadata = ()=> {
window.URL.revokeObjectURL(video.src);
var duration = video.duration;
file.duration = duration;
this.form.patchValue({duration:file.duration});
}
video.src = URL.createObjectURL(file);
}