3
I’m working on a player audio and need to know how to calculate the duration of various MP3’s that are selected on the user’s machine by a input
of the kind file
?
EDIT:
Follows my current code and does not return the correct value...
var audioElement2 = document.createElement('audio');
var fill;
var tamanho = 0;
$("#file666").change(function() {
fill = this.files.length;
for (var i = 0; i < fill; i++) {
file3[i] = this.files[i];
fileB = URL.createObjectURL(file3[i]);
audioElement2.setAttribute('src', fileB);
$(audioElement2).on("loadedmetadata", function () {
tamanho = tamanho + parseInt(audioElement2.duration);
});
}
$("#musicas").html("Músicas Carregadas: " + fill + " (Tempo Total: " + tamanho + ")");
});
I’m trying to use a loop for with a variable summing all mp3 but it doesn’t work, it returns "0" as a result...
Apparently it is only possible to read the duration afterward that the audio was injected into
src
tag<audio>
. I tested some libraries to read the ID3 that allow to read the properties of eachthis.files[i]
, but often the informationLength
does not appear in the MP3 file.– brasofilo
I had thought about answering, but since Tony already killed the riddle, I leave the links to my research: 1, 2, 3, 4, 5
– brasofilo