ReadFromFile() приватный Метод

Reads the ID3 v1.0 or v1.1 tag attached to a file from a given FileStream.
private ReadFromFile ( FileStream stream ) : bool
stream System.IO.FileStream The FileStream reading the file. It should support both seeking and reading.
Результат bool
Пример #1
0
        /// <summary>
        /// Writes the information provided in the TagInformation object
        /// to the given FileStream in ID3v1.1 format.
        /// </summary>
        /// <param name="stream">The FileStream that can read and write to the file. Must also support seeking.</param>
        /// <param name="tag">The TagInformation object containing the tag information. </param>
        private void WriteToFile(FileStream stream)
        {
            if(!(stream.CanRead && stream.CanSeek && stream.CanSeek))
                throw (new ArgumentException("The passed Stream object must support seeking, reading and writing."));

            ID3v1Tag tagInformation=new ID3v1Tag();
            if(!tagInformation.ReadFromFile(stream))
                stream.Seek(stream.Length, SeekOrigin.Begin);
            else
                stream.Seek(stream.Length-128, SeekOrigin.Begin);

            stream.Write(Encoding.GetEncoding("ISO-8859-1").GetBytes("TAG"), 0, 3);
            byte[] b=new byte[0];
            if(Title!="")
                b=Encoding.GetEncoding("ISO-8859-1").GetBytes(Title);
            for(int i=0;i<30;i++)
            {
                if(i<b.Length)
                    stream.WriteByte(b[i]);
                else
                    stream.WriteByte(0);
            }
            b=new byte[0];
            if(Artist!="")
                b=Encoding.GetEncoding("ISO-8859-1").GetBytes(Artist);
            for(int i=0;i<30;i++)
            {
                if(i<b.Length)
                    stream.WriteByte(b[i]);
                else
                    stream.WriteByte(0);
            }
            b=new byte[0];
            if(Album!="")
                b=Encoding.GetEncoding("ISO-8859-1").GetBytes(Album);
            for(int i=0;i<30;i++)
            {
                if(i<b.Length)
                    stream.WriteByte(b[i]);
                else
                    stream.WriteByte(0);
            }
            b=new byte[0];
            if(Year!="")
                b=Encoding.GetEncoding("ISO-8859-1").GetBytes(Year);
            for(int i=0;i<4;i++)
            {
                if(i<b.Length)
                    stream.WriteByte(b[i]);
                else
                    stream.WriteByte(0);
            }
            b=new byte[0];
            if(Comment!="")
                b=Encoding.GetEncoding("ISO-8859-1").GetBytes(Comment);
            for(int i=0;i<28;i++)
            {
                if(i<b.Length)
                    stream.WriteByte(b[i]);
                else
                    stream.WriteByte(0);
            }
            stream.WriteByte(0);
            stream.WriteByte(TrackNumber);
            stream.WriteByte(GenreCode);
        }
Пример #2
0
        /// <summary>
        /// Writes the information provided in the TagInformation object
        /// to the given FileStream in ID3v1.1 format.
        /// </summary>
        /// <param name="stream">The FileStream that can read and write to the file. Must also support seeking.</param>
        /// <param name="tag">The TagInformation object containing the tag information. </param>
        private void WriteToFile(FileStream stream)
        {
            if (!(stream.CanRead && stream.CanSeek && stream.CanSeek))
            {
                throw (new ArgumentException("The passed Stream object must support seeking, reading and writing."));
            }

            ID3v1Tag tagInformation = new ID3v1Tag();

            if (!tagInformation.ReadFromFile(stream))
            {
                stream.Seek(stream.Length, SeekOrigin.Begin);
            }
            else
            {
                stream.Seek(stream.Length - 128, SeekOrigin.Begin);
            }

            stream.Write(Encoding.GetEncoding("ISO-8859-1").GetBytes("TAG"), 0, 3);
            byte[] b = new byte[0];
            if (Title != "")
            {
                b = Encoding.GetEncoding("ISO-8859-1").GetBytes(Title);
            }
            for (int i = 0; i < 30; i++)
            {
                if (i < b.Length)
                {
                    stream.WriteByte(b[i]);
                }
                else
                {
                    stream.WriteByte(0);
                }
            }
            b = new byte[0];
            if (Artist != "")
            {
                b = Encoding.GetEncoding("ISO-8859-1").GetBytes(Artist);
            }
            for (int i = 0; i < 30; i++)
            {
                if (i < b.Length)
                {
                    stream.WriteByte(b[i]);
                }
                else
                {
                    stream.WriteByte(0);
                }
            }
            b = new byte[0];
            if (Album != "")
            {
                b = Encoding.GetEncoding("ISO-8859-1").GetBytes(Album);
            }
            for (int i = 0; i < 30; i++)
            {
                if (i < b.Length)
                {
                    stream.WriteByte(b[i]);
                }
                else
                {
                    stream.WriteByte(0);
                }
            }
            b = new byte[0];
            if (Year != "")
            {
                b = Encoding.GetEncoding("ISO-8859-1").GetBytes(Year);
            }
            for (int i = 0; i < 4; i++)
            {
                if (i < b.Length)
                {
                    stream.WriteByte(b[i]);
                }
                else
                {
                    stream.WriteByte(0);
                }
            }
            b = new byte[0];
            if (Comment != "")
            {
                b = Encoding.GetEncoding("ISO-8859-1").GetBytes(Comment);
            }
            for (int i = 0; i < 28; i++)
            {
                if (i < b.Length)
                {
                    stream.WriteByte(b[i]);
                }
                else
                {
                    stream.WriteByte(0);
                }
            }
            stream.WriteByte(0);
            stream.WriteByte(TrackNumber);
            stream.WriteByte(GenreCode);
        }