I've been trying for a long time to get the audio time (seconds) of a mp3 file upload in my Angular 2 App.
I've tried some different approaches (one of them), but i haven't been able to get it to work yet.
I was hoping to do it the Angular way - without calling document.querySelector(...)
or window.URL
for the URL.createObjectURL()
.
If i try with @ViewChild('file')
and a function on the field called with (change)
and call it with $event and the ViewChild:
<input #file type="file" class="form-control-file" (change)="setFileField($event, file)">
None of them contains the duration data, but i am able to get the file data through the event:
let files: FileList = event.target.files;
let file: File = files[0];
// File data from the event
lastModified: 1526819830000
lastModifiedDate: Sun May 20 2018 14:37:10 GMT+0200 (CEST) {}
name: "Det lægende samspil mellem det ydre og det indre mørke_pt1 - med Anders Laugesen.mp3"
size: 18792325
type: "audio/mp3"
If i wait and try to loop through the FormGroup data on the (ngSubmit)
, the data isn't there as well.
I've read about an event called (loadedmetadata)
but i can't get it to function in my app.
What should i do to get the duration of this file upload in an Angular 2 app, if i want to do it the Angular way?