Exemplo n.º 1
0
        private void WriteFrameHeader(int MinorVersion)
        {
            byte[] Buf;
            int    FrameIDLength = MinorVersion == 2 ? 3 : 4; // Length of FrameID according to version
            string Temp          = _FrameID;

            // if minor version of ID3 were 2, the frameID is 3 character length
            if (MinorVersion == 2)
            {
                Temp = FramesInfo.Get3CharID(Temp);
                if (Temp == null) // This frame is not availabe in this version
                {
                    return;
                }
            }

            Tag.WriteText(Temp, TextEncodings.Ascii, false); // Write FrameID
            Buf = BitConverter.GetBytes(Length);
            Array.Reverse(Buf);
            if (MinorVersion == 2)
            {
                Tag.FS.Write(Buf, 1, Buf.Length - 1); // Write Frame Size
            }
            else
            {
                Tag.FS.Write(Buf, 0, Buf.Length); // Write Frame Size
            }
            if (MinorVersion != 2)
            {
                // If newer than version 2 it have Flags
                Buf = BitConverter.GetBytes((ushort)_FrameFlags);
                Array.Reverse(Buf);
                Tag.FS.Write(Buf, 0, Buf.Length); // Write Frame Flag
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get header of current frame according to specific Size
        /// </summary>
        /// <param name="MinorVersion">Minor version of ID3v2</param>
        /// <returns>MemoryStream contain frame header</returns>
        protected MemoryStream FrameHeader(int MinorVersion)
        {
            byte[]       Buf;
            MemoryStream ms            = new MemoryStream();
            int          FrameIDLength = MinorVersion == 2 ? 3 : 4; // Length of FrameID according to version
            string       Temp          = _FrameID;

            // if minor version of ID3 were 2, the frameID is 3 character length
            if (MinorVersion == 2)
            {
                Temp = FramesInfo.Get3CharID(Temp);
                if (Temp == null) // This frame is not availabe in this version
                {
                    return(null);
                }
            }

            ms.Write(Encoding.ASCII.GetBytes(Temp), 0, FrameIDLength); // Write FrameID
            Buf = BitConverter.GetBytes(Length);
            Array.Reverse(Buf);
            if (MinorVersion == 2)
            {
                ms.Write(Buf, 1, Buf.Length - 1); // Write Frame Size
            }
            else
            {
                ms.Write(Buf, 0, Buf.Length); // Write Frame Size
            }
            if (MinorVersion != 2)
            {
                // If newer than version 2 it have Flags
                Buf = BitConverter.GetBytes((ushort)_FrameFlags);
                Array.Reverse(Buf);
                ms.Write(Buf, 0, Buf.Length); // Write Frame Flag
            }

            return(ms);
        }