17

I´m programming a little media player with a song library. Now I need to get the properties of a mp3,wma file, like the artist name or the song duration.

What is the best way to get this information?

Waren
  • 293
  • 2
  • 5
  • 10

2 Answers2

27

You can examine the ID3 tag of the mp3s. The taglib-sharp library is great for doing so. Source code available (here). Example code:

TagLib.File tagFile = TagLib.File.Create(pathtofile);
string artist = tagFile.Tag.FirstAlbumArtist;
string album = tagFile.Tag.Album;
string title = tagFile.Tag.Title;
...

Not sure if tag-lib supports .wma though... Tag-lib can however be ported to silverlight (if needed).

Avada Kedavra
  • 8,523
  • 5
  • 32
  • 48
  • I´ve downloaded this ID3 library and added it to my project. – Waren Jun 28 '11 at 13:18
  • But It says that the AssemblyInfo.cs and the *.snk is missing. How do I fix that? Anyway this library is very effectiv and easy to use. Thank you for that hint. – Waren Jun 28 '11 at 13:19
  • How can I Length mp3 file . I use this : ` string lengh = tagFile.Length.ToString();` but its return zero.???? – osman Rahimi Apr 16 '15 at 12:17
  • 1
    Waren, if you delete the snk file, then open up the AssemblyInfo.cs file and delete these two lines,[assembly:AssemblyDelaySign(false)] [assembly:AssemblyKeyFile("taglib-sharp.snk")]. This is of course respecting the original authors and only doing this for learning and not profit. Have fun. – PHenry Feb 09 '17 at 03:54
4

using an ID3 library. A quick google gave me: csid3lib

RvdK
  • 19,580
  • 4
  • 64
  • 107