Esempio n. 1
0
        internal override void Read(int TagLength)
        {
            if(!read) {
                tagFlags = new Dictionary<string, V23Flags>();

                if(hasExtHeader) {
                    // consuming the extended header, but not caring about it
                    byte[] exHeader = new byte[10];
                    mp3.Read(exHeader, 0, exHeader.Length);
                }

                while(true) {
                    byte[] rawFrameID = new byte[4];
                    byte[] rawSize = new byte[4];
                    byte[] rawFlags = new byte[2];
                    byte[] frameData;

                    mp3.Read(rawFrameID, 0, rawFrameID.Length);
                    string frameID = Encoding.ASCII.GetString(rawFrameID);

                    if(badFrameID(frameID))
                        break;

                    mp3.Read(rawSize, 0, rawSize.Length);
                    int frameSize = getFrameSize(rawSize);

                    if(frameSize == -1)
                        break;

                    // discarding the language portion of the COM tag
                    if(frameID == "COMM") {
                        mp3.Position += 4;
                        frameSize -= 4;
                    }

                    // skipping the PRIV tag, too much of a pain.
                    if(frameID == "PRIV") {
                        mp3.Position += frameSize + 3;
                        continue;
                    }

                    frameData = new byte[frameSize];

                    mp3.Read(rawFlags, 0, rawFlags.Length);
                    tagFlags[frameID] = new V23Flags(rawFlags);

                    byte encByte = (byte)mp3.ReadByte();

                    mp3.Read(frameData, 0, frameData.Length);

                    if(frameID != "APIC") {
                        tags.Add(new Tag(frameID, frameData, encByte));
                    } else {
                        images.Add(getImage(frameData));
                    }

                    if((mp3.Position - 10) >= TagLength)
                        break;
                }
                Tags = tags.ToArray();
                Images = images.ToArray();
                read = true;
            }
        }
Esempio n. 2
0
        internal override void Read(int TagLength)
        {
            if (!read)
            {
                tagFlags = new Dictionary <string, V23Flags>();

                if (hasExtHeader)
                {
                    // consuming the extended header, but not caring about it
                    byte[] exHeader = new byte[10];
                    mp3.Read(exHeader, 0, exHeader.Length);
                }

                while (true)
                {
                    byte[] rawFrameID = new byte[4];
                    byte[] rawSize    = new byte[4];
                    byte[] rawFlags   = new byte[2];
                    byte[] frameData;

                    mp3.Read(rawFrameID, 0, rawFrameID.Length);
                    string frameID = Encoding.ASCII.GetString(rawFrameID);

                    if (badFrameID(frameID))
                    {
                        break;
                    }

                    mp3.Read(rawSize, 0, rawSize.Length);
                    int frameSize = getFrameSize(rawSize);

                    if (frameSize == -1)
                    {
                        break;
                    }

                    // discarding the language portion of the COM tag
                    if (frameID == "COMM")
                    {
                        mp3.Position += 4;
                        frameSize    -= 4;
                    }

                    // skipping the PRIV tag, too much of a pain.
                    if (frameID == "PRIV")
                    {
                        mp3.Position += frameSize + 3;
                        continue;
                    }

                    frameData = new byte[frameSize];

                    mp3.Read(rawFlags, 0, rawFlags.Length);
                    tagFlags[frameID] = new V23Flags(rawFlags);

                    byte encByte = (byte)mp3.ReadByte();

                    mp3.Read(frameData, 0, frameData.Length);

                    if (frameID != "APIC")
                    {
                        tags.Add(new Tag(frameID, frameData, encByte));
                    }
                    else
                    {
                        images.Add(getImage(frameData));
                    }

                    if ((mp3.Position - 10) >= TagLength)
                    {
                        break;
                    }
                }
                Tags   = tags.ToArray();
                Images = images.ToArray();
                read   = true;
            }
        }