As Mentioned in What is ID3, ID3 v2 made from frames. Each frame contains special information and have it own structure. In Professional Tag Editor Project in Tag Project inside ID3 folder. there is a class named ID3v2. The main usage of this class is to read/write ID3 v2 information. This class is very similar to ID3v1. But there's much more detail about this class. The code below is Load method of ID3v2 class. This method will load all frames in specified file. As you can see There's a TagStream class to read file. (TagStream inherited FileStream class to provide more comfortable class to read/write ID3 data). After opening file try to read ID3 v2 header and if the file contains ID3 try to load all frames (You can use filter see samples) inside file by ReadFrames method. public void Load() { Errors.Clear(); ClearAll(); TagStream ID3File = new TagStream(_FilePath, FileMode.Open); ReadHeader(ID3File); if (!HaveTag) // If file don't contain ID3v2 exit function { ID3File.Close(); return; } ReadFrames(ID3File, _OriginID3Length); ID3File.Close(); } Sometimes ID3 data contains some type of errors. As example an application use old FrameID in newer version or contains a non valid Frame data in this situations ID3v2 class provide error list and when try to load file first of all clear error list. Reading ID3 v2 Frames This is Diagram of frame classes that all of them inherited Frame class. Each frame class read specific type of frame some of them read more than one type. Click on image to see it in large mode.
To read frames of ID3, ID3v2 class use ReadFrames method. For each frame this method first reads FrameID and continue reading for Frame size and flags. finally if ReadFrames indicate the frame must read call AddFrame method. It will find a suitable class for that frame (According to FrameID) The class will continue to read frame. After reading, frame will add to special array that holds all frames. As an example AddFrame method find a TIT2 frame so it will read with TextFrame class and call TextFrame constructor also send TagStream(based on FileStream) to the class and TextFrame class continue to reading. public TextFrame(string FrameID, FrameFlags Flags, TagStream Data, int Length) : base(FrameID, Flags) { // If it was URL frame the TextEncoding is ascii and must not read if (IsUrl) TextEncoding = TextEncodings.Ascii; else { TextEncoding = (TextEncodings)Data.ReadByte(); Length--; if (!IsValidEnumValue(TextEncoding, ExceptionLevels.Error, FrameID)) return; } Text = Data.ReadText(Length, _TextEncoding); } There is more than 25 classes to read frames of ID3 that all of them is inside Tag project in ID3 folder. Some related classes is inside single file. All of them works as described in example. Making a class for each frame type lets editing data more comfortable and make debugging more easy. Also if need to support new type of frame there is no need to lots of coding. This is basic idea of how Professional Tag Editor works. There is so much feature that this project provide. You can take a look to Features to know more about them. |