Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Properties of a *.mp3 File in C#

Tags:

c#

.net

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?

like image 621
Waren Avatar asked Jun 28 '11 11:06

Waren


1 Answers

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).

like image 59
Avada Kedavra Avatar answered Oct 08 '22 03:10

Avada Kedavra