Beispiel #1
0
        /// <summary>
        /// Reads and returns a frame from a stream.
        /// </summary>
        /// <param name="stream">The stream to read from.</param>
        /// <param name="version">The ID3v2 version of the tag being parsed.</param>
        /// <returns>The frame read from the stream.</returns>
        public static ID3v2Frame ReadFrame(Stream stream, ID3Versions version)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            ID3v2Frame      frame      = null;
            FrameParameters parameters = new FrameParameters(version);

            byte[] header    = new byte[parameters.HeaderLength];
            char[] idChars   = new char[parameters.IDLength];
            byte[] sizeBytes = new byte[parameters.SizeLength];
            byte[] flags     = new byte[parameters.FlagsLength];
            byte[] frameData;
            string frameID;
            int    size;

            stream.Read(header, 0, header.Length);

            Array.Copy(header, 0, idChars, 0, idChars.Length);
            Array.Copy(header, parameters.IDLength, sizeBytes, 0, sizeBytes.Length);
            Array.Copy(header, parameters.IDLength + parameters.SizeLength, flags, 0, flags.Length);

            if (idChars[0] != 0x0)
            {
                frameID = new String(idChars);
                if (parameters.SizeIsSynchSafe)
                {
                    size = SynchsafeInteger.UnSynchsafe(sizeBytes);
                }
                else
                {
                    size = EncodedInteger.ToInt(sizeBytes);
                }

                frameData = new byte[size];
                stream.Read(frameData, 0, frameData.Length);

                FrameType frameType = FrameRegistry.GetFrameType(frameID, version);
                frame = FrameRegistry.GetNewFrame(frameType);

                frame.Initialize(flags, frameData, version);
            }
            else
            {
                frame = null;
            }

            return(frame);
        }
Beispiel #2
0
 /// <summary>
 /// Parses the raw frame data.
 /// </summary>
 /// <param name="frameData">The raw frame data.</param>
 /// <param name="version">The ID3v2 version of the tag being parsed.</param>
 protected override void ParseFrameData(byte[] frameData, ID3Versions version)
 {
     counter = EncodedInteger.ToInt(frameData);
 }