calculate lenght of an audio file

Multimedia related Tips and tricks you would like to share.

calculate lenght of an audio file

Postby luca1202 on Fri Jan 29, 2010 1:55 pm

Hello i'm new here and I have a question!!
I can't find the way to read the total lenght of a song because the module gb.sdl.sound doesn't have any function to do this!
now for calculate the total lenght I use an extern program (mplayer) but I want to eliminate this dependence.

how I can calculate the length in my program?
thanks
luca1202
 
Posts: 1
Joined: Fri Jan 29, 2010 1:51 pm

Re: calculate lenght of an audio file

Postby kokoko3k on Tue Feb 09, 2010 2:08 pm

Hi luca, i'm afraid i can't help you much, as Xt7player itself uses mplayer get info about media files.
I Guess you've got to read the file header, which is different on different audio file types.
Also, different mp3 files can have different headers too (see xing header for an example reference).

If you manage to write a library which doesn't uses mplayer i would be happy to take a look, mplayer sometimes fails in reporting currect values on mp3 files (mostly vbr ones).

Good gambas coding!
User avatar
kokoko3k
Site Admin
 
Posts: 271
Joined: Wed Nov 05, 2008 12:29 pm

Re: calculate lenght of an audio file

Postby Kasey42 on Sat Jan 14, 2012 12:57 pm

A sound file is encoded by length. Most mp3 files use up 128 or 256 kilobits of memory to store a singe second of data (audio). That number is in the file description, which you could easily obtain using a proper API to your operating system. Also, you'll need the total filesize, which is also obtainable. Now, the last step? Divide the filesize by the bit rate, and you have the length of the song.
Kasey42
 
Posts: 1
Joined: Sat Jan 14, 2012 12:10 pm


Return to Howtos, Tips&Tricks

Who is online

Users browsing this forum: No registered users and 1 guest

cron

SourceForge.net Logo