160

What's a quick and easy way to view and edit ID3 tags (artist, album, etc.) using C#?

7 Answers 7

196

Thirding TagLib Sharp.

TagLib.File f = TagLib.File.Create(path);
f.Tag.Album = "New Album Title";
f.Save();
4
  • 1
    Can anybody tell me how to set Artist property? There are a lot of related properties (FirstArtist, Artist, JointedArtists, FirstPerformer) and almost all of them are read-only or deprecated...
    – Laserson
    Oct 14, 2010 at 17:24
  • 3
    A bit late, but you can add the performers/artists by the following: mp3.Tag.Performers = new string[] { "Performer 1", "Performer 2", "Performer 3" };
    – nokturnal
    Aug 15, 2011 at 20:28
  • Does this library support modern ID3v2 tags? Simucal's snippet suggests not (unless he just took part of it).
    – James
    May 18, 2013 at 18:38
  • TagLib is GPL. This is hardly an appropriate answer here. Sep 4, 2018 at 8:21
67

TagLib Sharp is pretty popular.

As a side note, if you wanted to take a quick and dirty peek at doing it yourself.. here is a C# snippet I found to read an mp3's tag info.

class MusicID3Tag

{

    public byte[] TAGID = new byte[3];      //  3
    public byte[] Title = new byte[30];     //  30
    public byte[] Artist = new byte[30];    //  30 
    public byte[] Album = new byte[30];     //  30 
    public byte[] Year = new byte[4];       //  4 
    public byte[] Comment = new byte[30];   //  30 
    public byte[] Genre = new byte[1];      //  1

}

string filePath = @"C:\Documents and Settings\All Users\Documents\My Music\Sample Music\041105.mp3";

        using (FileStream fs = File.OpenRead(filePath))
        {
            if (fs.Length >= 128)
            {
                MusicID3Tag tag = new MusicID3Tag();
                fs.Seek(-128, SeekOrigin.End);
                fs.Read(tag.TAGID, 0, tag.TAGID.Length);
                fs.Read(tag.Title, 0, tag.Title.Length);
                fs.Read(tag.Artist, 0, tag.Artist.Length);
                fs.Read(tag.Album, 0, tag.Album.Length);
                fs.Read(tag.Year, 0, tag.Year.Length);
                fs.Read(tag.Comment, 0, tag.Comment.Length);
                fs.Read(tag.Genre, 0, tag.Genre.Length);
                string theTAGID = Encoding.Default.GetString(tag.TAGID);

                if (theTAGID.Equals("TAG"))
                {
                    string Title = Encoding.Default.GetString(tag.Title);
                    string Artist = Encoding.Default.GetString(tag.Artist);
                    string Album = Encoding.Default.GetString(tag.Album);
                    string Year = Encoding.Default.GetString(tag.Year);
                    string Comment = Encoding.Default.GetString(tag.Comment);
                    string Genre = Encoding.Default.GetString(tag.Genre);

                    Console.WriteLine(Title);
                    Console.WriteLine(Artist);
                    Console.WriteLine(Album);
                    Console.WriteLine(Year);
                    Console.WriteLine(Comment);
                    Console.WriteLine(Genre);
                    Console.WriteLine();
                }
            }
        }
3
26

UltraID3Lib...

Be aware that UltraID3Lib is no longer officially available, and thus no longer maintained. See comments below for the link to a Github project that includes this library

//using HundredMilesSoftware.UltraID3Lib;
UltraID3 u = new UltraID3();
u.Read(@"C:\mp3\song.mp3");
//view
Console.WriteLine(u.Artist);
//edit
u.Artist = "New Artist";
u.Write();
6
  • +1 This is the best library by far - since 'UltraID3Lib supports most all of the seventy-four types of frames specified in the ID3 v2.3' as well as the early ID3v1 tags. Best answer.
    – James
    May 18, 2013 at 18:33
  • +1 This is much easier to use and simpler way to deal with mp3 metadata
    – amrswalha
    Aug 15, 2013 at 9:21
  • 1
    I used this recently and it works awesome and does not burden the process. It's fast and easy to use and accounts for just about every tag that exists in ID3 versions 1 and 2 (you can use both at once or just one or the other). It does way more than I needed. It also had a very comprehensive help file. I will recommend this to everyone. Sep 12, 2013 at 18:59
  • Greetings; Link is inaccessible. Is UltraID3Lib Discontinued?
    – user2225495
    Jun 7, 2018 at 12:02
  • I found a version of UltraID3Lib included in this GitHub project. github.com/clementboone/MyWindowsMediaPlayer The project contains an UltraID3Lib folder that is the complete contents of the zip file that used to be available.
    – Matt
    Jun 7, 2018 at 17:01
15

TagLib Sharp has support for reading ID3 tags.

2
  • I started using TagLib sharp based on the recommendation here and it worked great for my application (which was read-only of MP3 info).
    – greg7gkb
    Oct 22, 2008 at 7:41
  • See hewins's answer below for the new link location Dec 27, 2010 at 4:23
2

I wrapped mp3 decoder library and made it available for .net developers. You can find it here:

http://sourceforge.net/projects/mpg123net/

Included are the samples to convert mp3 file to PCM, and read ID3 tags.

2

ID3.NET implemented ID3v1.x and ID3v2.3 and supports read/write operations on the ID3 section in MP3 files. There's also a NuGet package available.

1

Audio Tools Library (ATL) is the best. Don't use TagLib sharp. Its has limited support and can't handle chapters. The nuget package is here for ATL. I tried several things, but ATL was the only one that could do everything I needed.

Not the answer you're looking for? Browse other questions tagged or ask your own question.