tags:

views:

1404

answers:

2

I'm using TagLib# to get ID3 tag data from some MP3s, but what I can't seem to do is find the length of the MP3. How can I find the length of an MP3 in C#?

+4  A: 

Hi,

This article may help you

Reading MP3 Headers in C#

Salgar
this is not really working for me... the lenght returned by the lib is incorrect of a few seconds
marcgg
Parsing MP3s is something I'd rather have in a library, than copied and pasted from code written in 2001.
J. Pablo Fernández
this method uses the file length to calculate the duration. this is an incorrect approach since for example adding an album art to the mp3 file increases the file length, but it does not effect the duration. this method fails at this point.
davsan
broken link, please check...
cevik
+4  A: 

TagLib# exposes this information TagLib.File.Properties.Duration

dwynne
That was easy to get it to work, but it's returning about 70% of the real duration of all the files I tried it with.
J. Pablo Fernández
I can't say I've tested it tbh so you could be right. I get the impression calculating duration from headers is an inexact science.
dwynne
I've tested taglib-sharp and it was max. 1 seconds wrong. this library does not use the file length to get the duration, so i'll definitely go with this.
davsan