How to get audio file duration before uploading ?
I'd like to get audio file metadata to store those informations in my database, but I don't really know how to proceed.
I tried to create a new Audio() and to set its src to some url, in order to easily get the duration, but fileitem object generated by angular-file-upload doesn't seem to have any sort or uri/blob.
Any help ?
@BriceN I also need audio duration before upload to it display beneath ng-thumb... any hacks you got ??
Hi @BriceN and @BahodurSaidov, a simple solution should be add onAfterAddingFile a function that handle FileItem return by angular-file-upload and then create a new Audio FIle. With this, you should be able to resolve:
uploader.onAfterAddingFile = function(fileItem) {
console.info('onAfterAddingFile', fileItem);
var urlSt = URL.createObjectURL(fileItem._file);
var audio = new Audio(urlSt);
//Do what you want
};
Can find a example, on plunk
Hi @CaosZero , you were right ! I struggled with the asynchronous audio object, finally got it working ! here is my final code:
uploader.onAfterAddingFile = function(fileItem) {
console.info('onAfterAddingFile', fileItem);
var urlSt = URL.createObjectURL(fileItem._file);
var audio = new Audio(urlSt);
// fileItem.file.audioDuration = audio.duration; //won't work
audio.addEventListener('loadeddata',function(){
fileItem.file.audioDuration = audio.duration;
$scope.$apply();//required to update view
});
Thank you @BriceN you can have a look too if you are still in this problem.