Click here to Skip to main content
Licence 
First Posted 2 Jun 2005
Views 43,596
Bookmarked 40 times

ID3v1.1 Tag Editor Class

By | 2 Jun 2005 | Article
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

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

About the Author

Angren Aldaron



Germany Germany

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralNot working Using Visual studio 2010 Pinmembermicheljansen4:59 26 Jan '11  
GeneralMy vote of 5 PinmemberMidax7:19 5 Jul '10  
GeneralOne little problem Pinmemberconemajstor23:08 26 Apr '07  
QuestionText File Properties Pinmembereli123455:19 23 Oct '06  
I would like to perform the same but for text file (*.txt).
Can anyone help me implement it?
 
El.
Generalyet another id31 lib..... PinmemberMP3Observer22:19 2 Jun '05  
GeneralRe: yet another id31 lib..... PinmemberAngren Aldaron2:28 3 Jun '05  
GeneralUse bytes instead of chars for length checks Pinmemberreinux21:25 2 Jun '05  
GeneralRe: Use bytes instead of chars for length checks PinmemberRudolfHenning23:31 2 Jun '05  
GeneralRe: Use bytes instead of chars for length checks Pinmemberreinux23:34 2 Jun '05  
GeneralRe: Use bytes instead of chars for length checks PinmemberAngren Aldaron2:26 3 Jun '05  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 2 Jun 2005
Article Copyright 2005 by Angren Aldaron
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid