示例#1
0
        private void setvalues(FrameReader reader)
        {
            this.frameCount = reader.FrameCount;
            this.header = reader.TagHeader;
            this.title = reader.Read<string>("TIT2", ReadString, null);
            this.artist = reader.Read<string>("TPE1", ReadString, null);
            this.album = reader.Read<string>("TALB", ReadString, null);
            this.year = reader.Read<string>("TYER", ReadString, null);
            this.trackstring = reader.Read<string>("TRCK", ReadString, null);

            if (trackstring == null)
            {
                this.tracknumber = -1;
            }
            else if (trackstring.Contains("/"))
            {
                string s = trackstring.Substring(0, trackstring.IndexOf('/'));

                this.tracknumber = -1;
                int.TryParse(s, out this.tracknumber);
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < trackstring.Length; i++)
                {
                    if (char.IsDigit(trackstring[i]))
                        sb.Append(trackstring[i]);
                }
                this.tracknumber = -1;
                int.TryParse(sb.ToString(), out this.tracknumber);
            }
        }
示例#2
0
 public static bool IsEmpty(TagHeader item)
 {
     return item.isempty;
 }
示例#3
0
 static TagHeader()
 {
     empty = new TagHeader(new Version(), (TagFlags)0, 0, 0);
     empty.isempty = true;
 }
示例#4
0
        public FrameInfo(Stream stream, TagHeader header, bool checkUnsynchronisation)
        {
            byte[] buffer = new byte[10];
            stream.Read(buffer, 0, 10);

            this.identifier = Encoding.ASCII.GetString(buffer, 0, 4);
            this.statusflags = (FrameStatusFlag)buffer[8];
            this.formatflags = (FrameFormatFlags)buffer[9];

            int sizeS = BinaryConverter.ToInt32(buffer, 4, true); // sizeS <= sizeU
            int sizeU = BinaryConverter.ToInt32(buffer, 4, false); // sizeU >= sizeS
            this.size = sizeS;

            if (sizeS != sizeU && checkUnsynchronisation)
            {
                int maxsize = header.Size - (int)(stream.Position - header.FirstFramePosition);
                long p = stream.Position;

                if (sizeU == maxsize)
                {
                    stream.Seek(sizeS, SeekOrigin.Current);
                    BinaryConverter.Skip(0, stream, header.FirstFramePosition + (long)header.Size);
                    FrameInfo frameS = new FrameInfo(stream, header, false);
                    stream.Seek(p, SeekOrigin.Begin);

                    if (!char.IsLetterOrDigit(frameS.Identifier, 0) ||
                        !char.IsLetterOrDigit(frameS.Identifier, 1) ||
                        !char.IsLetterOrDigit(frameS.Identifier, 2) ||
                        !char.IsLetterOrDigit(frameS.Identifier, 3) ||
                        frameS.Identifier != frameS.Identifier.ToUpper())
                    {
                        size = sizeU;
                    }
                }
                else
                {
                    stream.Seek(sizeS, SeekOrigin.Current);
                    BinaryConverter.Skip(0, stream, header.FirstFramePosition + (long)header.Size);
                    FrameInfo frameS = new FrameInfo(stream, header, false);
                    stream.Seek(p, SeekOrigin.Begin);

                    stream.Seek(sizeU, SeekOrigin.Current);
                    BinaryConverter.Skip(0, stream, header.FirstFramePosition + (long)header.Size);
                    FrameInfo frameU = new FrameInfo(stream, header, false);
                    stream.Seek(p, SeekOrigin.Begin);

                    if (char.IsLetterOrDigit(frameS.Identifier, 0) &&
                        char.IsLetterOrDigit(frameS.Identifier, 1) &&
                        char.IsLetterOrDigit(frameS.Identifier, 2) &&
                        char.IsLetterOrDigit(frameS.Identifier, 3) &&
                        frameS.Identifier == frameS.Identifier.ToUpper())
                    {
                        size = sizeS;
                    }
                    else if (char.IsLetterOrDigit(frameU.Identifier, 0) &&
                        char.IsLetterOrDigit(frameU.Identifier, 1) &&
                        char.IsLetterOrDigit(frameU.Identifier, 2) &&
                        char.IsLetterOrDigit(frameU.Identifier, 3) &&
                        frameU.Identifier == frameU.Identifier.ToUpper())
                    {
                        size = sizeU;
                    }
                    else
                        throw new Exception("An error occured due to an invalid Unsynchronized integer.");
                }
            }

            this.position = stream.Position;
            stream.Seek(size, SeekOrigin.Current);
        }