Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
120 user(s) are online (63 user(s) are browsing Forums)

Members: 0
Guests: 120

more...

Headlines

 
  Register To Post  

Obtain mp3 info?
Home away from home
Home away from home


See User information
Is there an easy/smart way of obtaining the lenght of an mp3 song? In minutes that is and not file lengt.

X5000
Go to top
Re: Obtain mp3 info?
Home away from home
Home away from home


See User information
deleted so one who quickly glances over this thread doesn't use this completely useless code (for the OP's questionthat is)

the right answer will follow later in this thread


Also, be sure you are not truncating/rounding the time when calculating minutes in the divide by 60 division...








OK, before someone thinks i can code
Here's the source

Not sure if it is what you are looking for

EDIT: Removed useless code


Edited by Raziel on 2011/12/5 22:01:19
People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
Go to top
Re: Obtain mp3 info?
Just can't stay away
Just can't stay away


See User information
Using mpega.library:
#include <libraries/mpega.h>
#include <proto/mpega.h>

static const MPEGA_CTRL mpa_ctrl = {
    
NULL,
    { 
FALSE, { 1244100 }, { 1244100 } },
    { 
FALSE, { 1244100 }, { 1244100 } },
    
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
Go to top
Re: Obtain mp3 info?
Just can't stay away
Just can't stay away


See User information
Version using mpg123.library (untested):
#include <libraries/mpg123.h>
#include <proto/mpg123.h>

int32 GetMP3Duration (CONST_STRPTR filename) {
    
mpg123_handle *mh;
    
int32 ms_duration 0;
    
mh mpg123_new(NULLNULL);
    if (
mh) {
        if (
mpg123_open(mhfilename) == MPG123_OK) {
            
mpg123_frameinfo fi;
            
int32 samples;
            if (
mpg123_info(mh, &fi) == MPG123_OK &&
                (
samples mpg123_length(mh)) >= 0)
            {
                
ms_duration = ((int64)length 1000) / fi.rate;
            }
            
mpg123_close(mh);
        }
        
mpg123_delete(mh);
    }
    return 
ms_duration;
}


Go to top
Re: Obtain mp3 info?
Home away from home
Home away from home


See User information
Thanks guys. I will see what i can make out of this.

X5000
Go to top
Re: Obtain mp3 info?
Just can't stay away
Just can't stay away


See User information
Quote:
Raziel wrote:

OK, before someone thinks i can code
Here's the source

Not sure if it is what you are looking for
At least you have proved you can use Google . Unfortunately:

- the code is in C# which is not available on AmigaOS - this particular snippet is not too difficult for a developer to translate to another language, though.

- what's worse is that the code will only work for MP3 files encoded to a particular bitrate and quality etc., as it assumes a direct relationship between the filesize in bytes (which is what it gets from the FileInfo object) and the playing time. I usually encode all my MP3 files to a bitrate of192 kb/s and using the joint stereo setting (not sure if the latter changes the byte length), so it would fail miserably with my files.

In short, Antique, you'd better go with one of salass00's methods.

Best regards,

Niels

Go to top
Re: Obtain mp3 info?
Just can't stay away
Just can't stay away


See User information
Quote:
- what's worse is that the code will only work for MP3 files encoded to a particular bitrate and quality


Or worse yet, it wont work with any mp3's at all. Raziel's code is meant for use with DSS files, not mp3's.

Go to top
Re: Obtain mp3 info?
Just can't stay away
Just can't stay away


See User information
Quote:
alfkil wrote:

Or worse yet, it wont work with any mp3's at all. Raziel's code is meant for use with DSS files, not mp3's.
Whooops - didn't even notice that .

Best regards,

Niels

Go to top
Re: Obtain mp3 info?
Home away from home
Home away from home


See User information
Hm, i can't seem to find the include files. Did not find them in the mpega file on the depot.

X5000
Go to top
Re: Obtain mp3 info?
Quite a regular
Quite a regular


See User information
This one has includes: http://aminet.net/package/util/libs/mpega_library

I suppose they work?

Go to top
Re: Obtain mp3 info?
Home away from home
Home away from home


See User information
Hehe

People are dying.
Entire ecosystems are collapsing.
We are in the beginning of a mass extinction.
And all you can talk about is money and fairytales of eternal economic growth.
How dare you!
– Greta Thunberg
Go to top
Re: Obtain mp3 info?
Just can't stay away
Just can't stay away


See User information
@Antique

I had OS4 includes for mpega.library generated for diskimage.device but it seems that I deleted them from the SVN when I switched to using mpg123.library instead. If you want I can regenerate and upload them for you tomorrow (shouldn't take many minutes to do).

Go to top
Re: Obtain mp3 info?
Just can't stay away
Just can't stay away


See User information
http://dl.dropbox.com/u/26599983/mpega_os4_includes.7z

Just extract the archive into "SDK:local/common/include".

Go to top
Re: Obtain mp3 info?
Home away from home
Home away from home


See User information
@salass00

Done that. But all i get is some errors when compiling. Not sure why. I have added the 2 includes aswell.
This one makes no difference if i have or not in the program....
#include <libraries/mpega.h>

The error code. Seems like some missing/wrong header file....?

/tmp/cc067KJ5.o: In function `GetMP3Duration.12662':
test2.c:(.text+0x1c42): undefined reference to `IMpega'
test2.c:(.text+0x1c46): undefined reference to `IMpega'
test2.c:(.text+0x1c52): undefined reference to `IMpega'
test2.c:(.text+0x1c56): undefined reference to `IMpega'
test2.c:(.text+0x1c8e): undefined reference to `IMpega'
/tmp/cc067KJ5.o:test2.c:(.text+0x1c92): more undefined references to `IMpega' follow

X5000
Go to top
Re: Obtain mp3 info?
Just can't stay away
Just can't stay away


See User information
@Antique

You need to add code for opening and closing the library.

struct Library *MPEGABase;
struct MpegaIFace *IMpega;
/* ... */
MPEGABase OpenLibrary("mpega.library"0);
IMpega = (struct MpegaIFace *)GetInterface(MPEGABase"main"1NULL);
if (
IMpega) {
    
/* mpega.library successfully opened,
       do something with it */
} else {
    
fprintf(stderr"Failed to open mpega.library!\\n");
}
DropInterface((struct Interface *)IMpega);
CloseLibrary(MPEGABase);

Go to top
Re: Obtain mp3 info?
Just popping in
Just popping in


See User information
@Antique

Maybe you should declare and open the library ?

Quote:

struct MpegaIFace IMpega = NULL;
struct Library *MPEGABase = NULL;

/* ... */

MPEGABase = OpenLibrary("mpega.library", 0);

IMpega = (struct MpegaIFace *)GetInterface(MPEGABase, "main", 1, NULL);



Edit: Salass00 faster + fixed libbase name

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project