Click here to Skip to main content
13,198,678 members (41,540 online)
Click here to Skip to main content
Add your own
alternative version

Stats

53K views
352 downloads
40 bookmarked
Posted 2 Jun 2005

ID3v1.1 Tag Editor Class

, 2 Jun 2005
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Angren Aldaron
Germany Germany
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralNot working Using Visual studio 2010 Pin
micheljansen26-Jan-11 4:59
membermicheljansen26-Jan-11 4:59 
GeneralMy vote of 5 Pin
Midax5-Jul-10 7:19
memberMidax5-Jul-10 7:19 
GeneralOne little problem Pin
conemajstor26-Apr-07 23:08
memberconemajstor26-Apr-07 23:08 
QuestionText File Properties Pin
eli1234523-Oct-06 5:19
membereli1234523-Oct-06 5:19 
Generalyet another id31 lib..... Pin
MP3Observer2-Jun-05 22:19
memberMP3Observer2-Jun-05 22:19 
GeneralRe: yet another id31 lib..... Pin
Angren Aldaron3-Jun-05 2:28
memberAngren Aldaron3-Jun-05 2:28 
GeneralUse bytes instead of chars for length checks Pin
reinux2-Jun-05 21:25
memberreinux2-Jun-05 21:25 
GeneralRe: Use bytes instead of chars for length checks Pin
RudolfHenning2-Jun-05 23:31
memberRudolfHenning2-Jun-05 23:31 
GeneralRe: Use bytes instead of chars for length checks Pin
reinux2-Jun-05 23:34
memberreinux2-Jun-05 23:34 
GeneralRe: Use bytes instead of chars for length checks Pin
Angren Aldaron3-Jun-05 2:26
memberAngren Aldaron3-Jun-05 2:26 

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.

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