views:

134

answers:

4

Hey all, how's it going?

I'm makin' a little mp3 player here and I've pretty much got everything covered. I would like to be able to display the duration of the song but am kinda confused as to go about doing so. I've searched around the net and have seen so many examples that seem so long which makes me wonder if there's an easier way to get the duration of a song?

A: 

The only way to make sure the duration of an MP3 is to decode it.

Especially when it's VBR encoded, it's hard to guess the length by the file size. Some MP3s have the length in the ID3 tag, so you can take that as a hint; but in my experience, even that's not always accurate.

balpha
A: 

Duplicate of this question [SO]

PaulB
Sorry about that PaulB. That link didn't show up in my search results - otherwise I wouldn't have posted this question.
baeltazor
No probs - we've all done it :)
PaulB
A: 

You need to decode the mp3. For a nice article on decoding mp3s see http://blog.bjrn.se/2008/10/lets-build-mp3-decoder.html It is not written for c# but is fairly complete.

If rolling your own library is not something you're interested in, the link to the other question has links to libraries that are worth looking at.

marco0009
+1  A: 

You may be interested in Mp3Sharp. I haven't used it much, but I see functions such as BitsPerSample, which may be useful for what you're trying to accomplish.

Corey