Jump to content

Possible to get music file length?

Recommended Posts

Is it possible to retrieve a mp3 or wav music file length? like 04:32


There should be a dll for it, although I had no luck finding it. Windows Media player has to get the song length some how. Other then that, the only way I can think of is to filegetsize and do some math to figure out how long the song is. But if you did it that way, then quality will be a issue with then file size. All I know is that windows media player does it as well as other players and I believe there is a dll some where to return the length of a Mp3 file.


Link to post
Share on other sites

For Mp3, it is the mp3 author's choice to code in the length in the ID tag, I believe.

But many utilities will calculate it for you.

For WAV, if you can access the header, you can calculate the length precisely.

If you know that it is 16 bit stereo, 44100 Sampling rate, such as CD quality, you can use:

Length in Seconds = (Size of File - Size of Header)/44100/2(for stereo)/(16*16)

Header is around 32 bytes I think, but there are exceptions.

(This is all from my memory -- Please correct me if I am wrong)


If I am too verbose, just say so. You don't need to run on and on.

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...