Пример #1
0
        internal override void Read(int TagLength)
        {
            if(!read) {
                tagFlags = new Dictionary<string, V24Flags>();

                if(hasExtHeader) {
                    // Once again, consuming the extended header but not caring about it.
                    byte[] rawHeaderLen = new byte[4];
                    byte[] extHeader;
                    int headerLen;
                    mp3.Read(rawHeaderLen, 0, rawHeaderLen.Length);
                    headerLen = (rawHeaderLen[0] << 21) + (rawHeaderLen[1] << 14) + (rawHeaderLen[2] << 7) + rawHeaderLen[3];
                    extHeader = new byte[headerLen];
                    mp3.Read(extHeader, 0, extHeader.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 V24Flags(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;
            }
        }
Пример #2
0
        internal override void Read(int TagLength)
        {
            if (!read)
            {
                tagFlags = new Dictionary <string, V24Flags>();

                if (hasExtHeader)
                {
                    // Once again, consuming the extended header but not caring about it.
                    byte[] rawHeaderLen = new byte[4];
                    byte[] extHeader;
                    int    headerLen;
                    mp3.Read(rawHeaderLen, 0, rawHeaderLen.Length);
                    headerLen = (rawHeaderLen[0] << 21) + (rawHeaderLen[1] << 14) + (rawHeaderLen[2] << 7) + rawHeaderLen[3];
                    extHeader = new byte[headerLen];
                    mp3.Read(extHeader, 0, extHeader.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 V24Flags(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;
            }
        }