In my angular form, I get my video or audio files by
(change)="fileSelected($event)
in .html form and
attachedFile = <File>event.target.files[0]
in .ts file that has name, type and size. How can I get audio/video duration time?
event.target.files[0] in .t" /> event.target.files[0] in .t" /> event.target.files[0] in .t"/>
In my angular form, I get my video or audio files by
(change)="fileSelected($event)
in .html form and
attachedFile = <File>event.target.files[0]
in .ts file that has name, type and size. How can I get audio/video duration time?
On
You can create an audio or video element dynamically based on selected file type and then can get other info. Here is the code...
fileSelected($event) {
attachedFile = <File>event.target.files[0]
let duration:any;
//here you can check the file type for attachedFile either video or audio
var video = document.createElement('video');
video.preload = 'metadata';
video.onloadedmetadata = function() {
window.URL.revokeObjectURL(video.src);
duration = video.duration; // here you could get the duration
}
video.src = URL.createObjectURL(attachedFile);
}
Try below code,