Get the Length of a mp3 file
OK, me again. Could someone help me with an algorithm to get the length (in seconds) of a mp3 file, or an already created library. I know an algorithm like this one:
(song_bytes*8)/(bit_rate)*1024 . The problem is, that it only works if it's encoded with LAME, and with other shows different sizes. Please help.
I'm absolutely no expert in this, but shouldn't the total time be stored as meta information in the mp3 file?Because I don't think, that every mp3 player is recalculating the time length for itself.
> I'm absolutely no expert in this, but shouldn't the
> total time be stored as meta information in the mp3
> file?
>
> Because I don't think, that every mp3 player is
> recalculating the time length for itself.
No, the 'total time' is not one of the standard meta data items in an MP3 file. It is not even easy to calculate since each frame can have a different sample rate (Note 1). One has to sum the length of each frame by extracting the number of samples and sample rate from each frame.
(Note 1) All the MP3 files I have ripped or downloaded have had the same sample rate for every frame but the spec says the sample rate can change in each frame.