Example #1
0
        private void Parse()
        {
            while (true)
            {
                var type = Reader.ReadByte();

                var last = (type & 0x80) == 0x80;

                if (last)
                {
                    break;
                }

                var length = BitConverterExtension.ToInt24(Reader.ReadBytes(3), 0);

                switch ((MetadataBlockType)type)
                {
                case MetadataBlockType.STREAMINFO: {
                    StreamInfo = StreamInfo.FromByteArray(Reader.ReadBytes(length));
                    break;
                }

                case MetadataBlockType.SEEKTABLE: {
                    Reader.ReadBytes(length);
                    break;
                }

                case MetadataBlockType.PICTURE: {
                    var picture = Picture.FromByteArray(Reader.ReadBytes(length));

                    Pictures[picture.PictureType] = picture;
                    break;
                }

                case MetadataBlockType.VORBIS_COMMENT: {
                    VorbisComment = VorbisComment.FromByteArray(Reader.ReadBytes(length));
                    break;
                }

                default: {
                    // Discard
                    Reader.ReadBytes(length);
                    break;
                }
                }
            }

            if (VorbisComment == null)
            {
                VorbisComment = new VorbisComment();
            }
            Frame = Reader.ReadBytes((int)(InMemoryByteArray.Length - InMemoryByteArray.Position));
        }