8

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#?

UnkwnTech
  • 88,102
  • 65
  • 184
  • 229
  • Kind of duplicated question; I tried to answer that here: http://stackoverflow.com/questions/383164/how-to-retrieve-duration-of-mp3-in-net/13269914#13269914 – Daniel Mošmondor Nov 09 '12 at 16:50

1 Answers1

12

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

NoWar
  • 36,338
  • 80
  • 323
  • 498
dwynne
  • 906
  • 1
  • 9
  • 14
  • 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. – Pablo Fernandez Dec 30 '09 at 21:33
  • 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 Jan 07 '10 at 15:37
  • 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. – aslı Mar 21 '10 at 19:41
  • I use NAudio instead to get proper duration for media files; the obtained information seem to be correct since it allowed me to implement a functionality that can "guess" a discid from a set of mp3 files which I can use to query album information from freedb... – Matze Mar 24 '16 at 08:50