Exemplo n.º 1
0
        /// <summary>
        /// Reads an ID3v2 tag from a stream. Returns null if no ID3v2 tag can be found
        /// in the stream.
        /// </summary>
        /// <param name="stream">The stream to read.</param>
        /// <returns>The tag read from the stream, or null if no ID3v2 tag can be found.</returns>
        public static ID3v2Tag ReadTag(Stream stream)
        {
            ID3Versions version = LookForTag(stream);
            ID3v2Tag    tag     = null;

            if ((version & ID3Versions.V2) == ID3Versions.V2)
            {
                tag = new ID3v2Tag();

                tag.headerFlags = ReadFlags(stream, version);

                int tagSize = ReadTagSize(stream);

                // Go to the first byte after the header
                stream.Seek(TAG_HEADER_LENGTH, SeekOrigin.Begin);

                while (stream.Position < tagSize)
                {
                    ID3v2Frame newFrame = ID3v2Frame.ReadFrame(stream, version);
                    if (newFrame != null)
                    {
                        tag.AddFrame(newFrame);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(tag);
        }