示例#1
0
        /// <summary>
        /// Reads tags for the given MP3
        /// </summary>
        /// <param name="Filename">FileInfo representation of the MP3</param>
        public ID3v2(FileInfo MP3)
        {
            byte[] header  = new byte[6];
            byte[] tagSize = new byte[4];
            File = MP3;

            using (FileStream fs = MP3.OpenRead()) {
                fs.Read(header, 0, header.Length);
                fs.Read(tagSize, 0, tagSize.Length);

                HasID3v2Data = Encoding.ASCII.GetString(header, 0, 3) == "ID3";

                if (!HasID3v2Data)
                {
                    Version = "N/A";
                    fs.Close();
                    return;
                }

                Version = string.Format("ID3v2.{0}.{1}", header[3], header[4]);
                Flags   = header[5];

                // converting syncsafe integer to a normal int
                int tagLength = (tagSize[0] << 21) + (tagSize[1] << 14) + (tagSize[2] << 7) + tagSize[3];

                VersionSupported = true;
                switch (Version)
                {
                case "ID3v2.2.0":
                    frames = new V22Frames(fs);
                    break;

                case "ID3v2.3.0":
                    frames = new V23Frames(fs, HasExtendedHeader);
                    break;

                case "ID3v2.4.0":
                    frames = new V24Frames(fs, HasExtendedHeader);
                    break;

                default:
                    VersionSupported = false;
                    frames           = null;
                    break;
                }

                frames.Read(tagLength);
                fs.Close();
            }
        }
示例#2
0
        /// <summary>
        /// Reads tags for the given MP3
        /// </summary>
        /// <param name="Filename">FileInfo representation of the MP3</param>
        public ID3v2(FileInfo MP3)
        {
            byte[] header = new byte[6];
            byte[] tagSize = new byte[4];
            File = MP3;

            using(FileStream fs = MP3.OpenRead()) {
                fs.Read(header, 0, header.Length);
                fs.Read(tagSize, 0, tagSize.Length);

                HasID3v2Data = Encoding.ASCII.GetString(header, 0, 3) == "ID3";

                if(!HasID3v2Data) {
                    Version = "N/A";
                    fs.Close();
                    return;
                }

                Version = string.Format("ID3v2.{0}.{1}", header[3], header[4]);
                Flags = header[5];

                // converting syncsafe integer to a normal int
                int tagLength = (tagSize[0] << 21) + (tagSize[1] << 14) + (tagSize[2] << 7) + tagSize[3];

                VersionSupported = true;
                switch(Version) {
                    case "ID3v2.2.0":
                        frames = new V22Frames(fs);
                        break;
                    case "ID3v2.3.0":
                        frames = new V23Frames(fs, HasExtendedHeader);
                        break;
                    case "ID3v2.4.0":
                        frames = new V24Frames(fs, HasExtendedHeader);
                        break;
                    default:
                        VersionSupported = false;
                        frames = null;
                        break;
                }

                frames.Read(tagLength);
                fs.Close();
            }
        }