示例#1
0
 /// <summary>
 /// Ensures that there is space for the tag at the end of the stream.
 /// </summary>
 /// <param name="stream">The stream to check.</param>
 private void EnsureSpace(Stream stream)
 {
     if (!ID3v1Tag.HasTag(stream))
     {
         stream.SetLength(stream.Length + TagLenth);
     }
 }
示例#2
0
        /// <summary>
        /// Reads an ID3v1 tag from a stream. Returns null if no ID3v1 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 ID3v1 tag can be found.</returns>
        public static ID3v1Tag ReadTag(Stream stream)
        {
            ID3v1Tag tag = null;

            if (HasTag(stream))
            {
                tag = new ID3v1Tag();
                byte[] bytes;

                bytes     = ReadFromFile(ID3v1Tag.TitleFieldLength, stream);
                tag.Title = BytesToString(bytes);

                bytes      = ReadFromFile(ID3v1Tag.ArtistFieldLength, stream);
                tag.Artist = BytesToString(bytes);

                bytes     = ReadFromFile(ID3v1Tag.AlbumFieldLength, stream);
                tag.Album = BytesToString(bytes);

                bytes    = ReadFromFile(ID3v1Tag.YearFieldLength, stream);
                tag.Year = BytesToString(bytes);

                bytes        = ReadFromFile(ID3v1Tag.ID3v1_1CommentsFieldLength, stream);
                tag.Comments = BytesToString(bytes);

                // Track Number
                bytes = ReadFromFile(2, stream);
                if (bytes[0] == 0x0)
                {
                    tag.TrackNumber = (int)bytes[1];
                }
                else
                {
                    tag.Comments += BytesToString(bytes);
                }

                // Genre
                bytes = ReadFromFile(1, stream);
                if ((sbyte)bytes[0] == -1)
                {
                    tag.GenreAsInt = -1;
                }
                else
                {
                    tag.GenreAsInt = (int)bytes[0];
                }
            }

            return(tag);
        }