Using
mpega.library:
#include <libraries/mpega.h>
#include <proto/mpega.h>
static const MPEGA_CTRL mpa_ctrl = {
NULL,
{ FALSE, { 1, 2, 44100 }, { 1, 2, 44100 } },
{ FALSE, { 1, 2, 44100 }, { 1, 2, 44100 } },
0,
0
};
int32 GetMP3Duration (CONST_STRPTR filename) {
MPEGA_STREAM *stream;
int32 ms_duration = 0;
stream = MPEGA_open((STRPTR)filename, (MPEGA_CTRL *)&mpa_ctrl);
if (stream) {
ms_duration = stream->ms_duration;
MPEGA_close(stream);
}
return ms_duration;
}
This function returns the duration of the MP3 file in milliseconds (1ms = 0.001s). Converting this to minutes is trivial enough that I don't think I have to provide code for this, plus you can then decide for yourself if you want to use rounding or not.
Note that not all MP3 files (IIRC) contain duration information so in this case the function will return 0 (same applies if the file can't be opened by mpega.library for some reason).
Edited by salass00 on 2011/12/4 10:34:57