Click here to Skip to main content
15,884,628 members
Articles / Programming Languages / C#
Article

ID3v1.1 Tag Editor Class

Rate me:
Please Sign up or sign in to vote.
4.06/5 (13 votes)
2 Jun 20053 min read 59.5K   408   40   10
A simple class for editing ID3v1 tags in files.

Introduction

Hello, and now here is my second waste of code for the community :), but at this time it should come in a bit handy for hobby developers. First, I only wanted to increase my programming experience. On second thought I needed something for my projects in the future. And I needed a tag editor for the ID3v1.1 standard. My tag editor class reduces editing these information to a minimum, and the only project about ID3v1 tags I found for C# on this server was a project which only is able to read these information.

Using the code

There are two classes: the tagger class Tagger and a small database for the genres GenreDB. The class Tagger has eleven public properties and one public method. Let's begin with the properties:

  • bool hasTag - indicates if the file has a tag. When you save the file it records if you want to have a tag in the future.
  • string Title - sets or reads the title. If the size is over 30 characters, it throws a FormatException.
  • string Artist - sets or reads the artist. If the size is over 30 characters, it throws a FormatException.
  • string Album - sets or reads the album. If the size is over 30 characters, it throws a FormatException.
  • string Year - sets or reads the year. If the size is over 4 characters, it throws a FormatException.
  • string Comment - sets or reads the comment. If the size is over 28 characters, it throws a FormatException.
  • string TitleNumber - sets or reads the title number. If the value is greater than 255 or smaller than 0, or the value is not a number, it throws a FormatException.
  • string GenreID - sets or reads the genre ID. If the value is greater than 255 or smaller than 0, or the value is not a number, it throws a FormatException.
  • string GenreName - reads the GenreID and returns the genre name as string. If there's an ID over 147, it returns an empty string.
  • string FullFilePath - returns the full path of the used file.
  • long FileSize - returns the actual file size.

And the single public method in this party is to write/update the file:

  • void WriteID3v11()

And now to the mentioned database for the genre (GenreDB). It has one static property and one static method. The use of it is very simple. First the static property:

  • static string[] GenreList - In this list, there are all genres specified in the ID3v1 standard. There are also the Winamp extensions in it. The order is like what is specified. So when you use this property like GenreDB.GenreList[3], you'll get the string "Dance". When you write GenreDB.GenreList[90] (one of the Winamp Extensions), you'll get the string "Avantgarde" (you'll find the order here in German, and in English here). Or you simply use the GenreList to enumerate the list with a foreach block or something.

The next is the method:

  • static string GetGenreID(string genre) - It has a string in its arguments. When you need the proper ID for a genre, you can try this method. If it doesn't find the proper element in the list, it will return an empty string.

Code samples

C#
Tagger myTagger = new Tagger("C:\\test.mp3");
myTagger.Artist = "me";
myTagger.Album = "i dont know";
myTagger.WriteID3v11();

You see, the use of it is very simple, but when you want to write the file, make sure myTagger.HasTag is true, otherwise it won't write your edits.

Point of interest

I'm not a starter, but I'm far away from an experienced programmer, so I learned many things. For example, I'm now able to read out of files byte by byte, and convert these bytes into the information I want. But I don't want to bother you, and want to let you use my code :). Have fun with it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralNot working Using Visual studio 2010 Pin
micheljansen26-Jan-11 4:59
micheljansen26-Jan-11 4:59 
GeneralMy vote of 5 Pin
Midax5-Jul-10 7:19
Midax5-Jul-10 7:19 
GeneralOne little problem Pin
conemajstor26-Apr-07 23:08
conemajstor26-Apr-07 23:08 
QuestionText File Properties Pin
eli1234523-Oct-06 5:19
eli1234523-Oct-06 5:19 
Generalyet another id31 lib..... Pin
MP3Observer2-Jun-05 22:19
MP3Observer2-Jun-05 22:19 
GeneralRe: yet another id31 lib..... Pin
Angren Aldaron3-Jun-05 2:28
Angren Aldaron3-Jun-05 2:28 
GeneralUse bytes instead of chars for length checks Pin
Rei Miyasaka2-Jun-05 21:25
Rei Miyasaka2-Jun-05 21:25 
GeneralRe: Use bytes instead of chars for length checks Pin
RudolfHenning2-Jun-05 23:31
RudolfHenning2-Jun-05 23:31 
GeneralRe: Use bytes instead of chars for length checks Pin
Rei Miyasaka2-Jun-05 23:34
Rei Miyasaka2-Jun-05 23:34 
GeneralRe: Use bytes instead of chars for length checks Pin
Angren Aldaron3-Jun-05 2:26
Angren Aldaron3-Jun-05 2:26 
Thanks for hint reinux. Will follow it.

At all, I know on my own that ID3v1.1 is old -
I'm a IT Specialist for system integration, progging does not belong to my job, but I know for normal what's on the market. You needn't say me whats old and what's new. This belongs to my first things to look about, the versions, and the alternatives -
, but this was only for warm up, now I only have to copy my way, for all other tag variants. I will improve my tagger class. I began this project 05/31/2005. 2 days for progging. I'm no specialist. I want build a ID3v2.4 Tag as long as a APE Tag support.

But Thanks at all for the comment. This was my first useful article for the community. My last articel was only sh*t (IP Adress filtering) :P.

Question to MP3Observer. How to calculate the length of ID3v2.4 tag. When I insert a tag with Winamp (ID3v2.3 but should be the same way) in the specification there is a Hex position whicht indicates the size, but I looked in the Winamp made tag. There wasn't the size, and there was no footer.

Life's sh*t, but the graphics are wunderful Smile | :)

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.