How ID3v1 class works ? 

Introduction
Professional Tag Editor
Features Overview
What is ID3 Tagging ?
What is WMA Tagging ?
Download
For Developer
Features
ID3 Controls
WMA Controls
Samples
How it works (ID3v1)
How it works (ID3v2)
How it works (WMA)
WMA vs. MP3
About
Version History
About / Permissions
Awards
Professional Tag Editor provides classes to read and write ID3 information. First you needs to know how ID3 store in file. To know this take a look at What is ID3 Tagging ?.

ID3v1 Class

ID3v1 Class Diagram in Visual Studio 2008Reading ID3v1 is very easier than ID3v2. To read this version of ID3 first must read the final 128 bytes of file to understand if file contains ID3v1.

There is a class named ID3v1 for this version of ID3. This class is in Tag project in ID3 folder. The right image is Diagram of this class in Visual Studio. As you can see this class provides all ID3v1 information as property every limits checks. It also have methods to Load/Save data.

ID3v1 class is isolated class and don't need any other class. It can be used for ID3v1. If you like to do so take a look at samples.

This method lets application to know if file contains ID3v1. As you can see in the code below first if file length was smaller than 128 bytes it doesn't contains ID3. Then seek the 128th final byte of file try to read 3 characters. (ReadText is a method to read specific length of string in File) if it was 'TAG' it means file contains ID3v1 data otherwise it's not.

public bool HaveID3v1()
{
   
if (this.Length < 128)
       
return false;
   
this.Seek(-128, SeekOrigin.End);
   
string Tag = ReadText(3, TextEncodings.Ascii);
   
return (Tag == "TAG");
 }

Every read and write operations do with TagStream class Instead of FileStream. TagStream class inherited FileStream and contains some additional method that in every read/write operation needed.

As you can see in the Load method of ID3v1 used TagStream to start reading file and fill variables.

public void Load()
{
   
TagStream FS = new TagStream(_FilePath, FileMode.Open);
   
if (!FS.HaveID3v1()) // HaveID3v1 go to beginning of ID3v1 if exist
   
{
        FS.Close();
        _HaveTag =
false;
       
return;
    }
    _Title = FS.ReadText(30,
TextEncodings.Ascii);
    FS.Seek(-95,
SeekOrigin.End);
    _Artist = FS.ReadText(30,
TextEncodings.Ascii);
    FS.Seek(-65,
SeekOrigin.End);
    _Album = FS.ReadText(30,
TextEncodings.Ascii);
    FS.Seek(-35,
SeekOrigin.End);
    _Year = FS.ReadText(4,
TextEncodings.Ascii);
    FS.Seek(-31,
SeekOrigin.End);
    _Comment = FS.ReadText(28,
TextEncodings.Ascii);
    FS.Seek(-2,
SeekOrigin.End);
    _TrackNumber = FS.ReadByte();
    _Genre = FS.ReadByte();
    FS.Close();
    _HaveTag =
true;
}

TagStream class can Read string from file and write them (Because strings in ID3 have special structure that don't let normal stream to use for reading them). ReadText method lets to read in any type of encodings.

And Properties of  this class may to force limits of ID3v1 for example Album name in ID3v1 must not be more than 30 characters so we can check it in Album property.

public string Album
{
    get{ return _Album; }
   
set
    {
   
    if (value.Length > 30)
       
    throw (new ArgumentException("Album Length must be less than 30 characters"));
        _Album =
value;
    }
}

Reading ID3v2 is somehow like ID3v1 but that's more complex and need more classes. If you like to know how Professional Tag Editor read ID3v2 Take a look at ID3v2 Reading.