/// <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); }
/// <summary> /// Returns the FrameType for the given frame ID and version. /// </summary> /// <param name="frameId">The frame ID string to look up.</param> /// <param name="version">The ID3v2 version to use.</param> /// <returns>The frame ID for the given FrameType and version.</returns> public static FrameType GetFrameType(string frameId, ID3Versions version) { return(FrameRegistry.GetFrameType(frameId, version)); }