ReadBlock() public method

Removes a set of tag types from the current instance. Gets a tag of a specified type from the current instance, optionally creating a new tag if possible. Gets a tag of a specified type from the current instance. Reads a specified number of bytes at the current seek position from the current instance.
In order to remove all tags from a file, pass as types.

Passing to does not guarantee the tag will be created. For example, trying to create an ID3v2 tag on an OGG Vorbis file will always fail.

It is safe to assume that if is not returned, the returned tag can be cast to the appropriate type.

This class merely accesses the tag if it exists. GetTag(TagTypes,bool) provides the option of adding the tag to the current instance if it does not exist.

It is safe to assume that if is not returned, the returned tag can be cast to the appropriate type.

This method reads the block of data at the current seek position. To change the seek position, use .

/// is less than zero. ///
public ReadBlock ( int length ) : ByteVector
length int /// A value specifying the number of bytes /// to read. ///
return ByteVector
Beispiel #1
0
 public Tag(File file, long position)
 {
     if (file == null)
     {
         throw new ArgumentNullException("file");
     }
     file.Mode = File.AccessMode.Read;
     if ((position < 0L) || (position > (file.Length - 0x80L)))
     {
         throw new ArgumentOutOfRangeException("position");
     }
     file.Seek(position);
     ByteVector data = file.ReadBlock(0x80);
     if (!data.StartsWith(FileIdentifier))
     {
         throw new CorruptFileException("ID3v1 data does not start with identifier.");
     }
     this.Parse(data);
 }
Beispiel #2
0
        //Additional info here http://gabriel.mp3-tech.org/mp3infotag.html
        //https://www.codeproject.com/Articles/8295/MPEG-Audio-Frame-Header

        /// <summary>See if the mp3 file is encoded using VBR. Not sure what to do with ABR...
        /// </summary>
        private bool IsVBR()
        {
            bool bVBR = false;

            if (currentFile.MimeType != "taglib/mp3")
            {
                return(false);
            }

            foreach (ICodec codec in currentFile.Properties.Codecs)
            {
                TagLib.Mpeg.AudioHeader header = (TagLib.Mpeg.AudioHeader)codec;
                //                if (header == null)
                //                    return;

                if (header.XingHeader.Present)
                {
                    currentFile.Mode = TagLib.File.AccessMode.Read;
                    long XingHeader = currentFile.Find(TagLib.Mpeg.XingHeader.FileIdentifier);
                    long Offset     = TagLib.Mpeg.XingHeader.XingHeaderOffset(header.Version, header.ChannelMode);
                    TagLib.Mpeg.XingHeader xing_header = TagLib.Mpeg.XingHeader.Unknown;
                    currentFile.Seek(XingHeader);// + Offset);
                    ByteVector xing_data = currentFile.ReadBlock(16);
                    if (xing_data.Count == 16 && xing_data.StartsWith(
                            TagLib.Mpeg.XingHeader.FileIdentifier))
                    {
                        xing_header = new TagLib.Mpeg.XingHeader(xing_data);
                    }

                    int  Flags          = BitConverter.ToInt32(xing_data.Take(8).ToArray().Reverse().ToArray(), 0);
                    bool FramesPresent  = (Flags & 0x0001) > 0;
                    bool BytesPresent   = (Flags & 0x0002) > 0;
                    bool TOCPresent     = (Flags & 0x0004) > 0;
                    bool QualityPresent = (Flags & 0x0008) > 0;
                    long LameHeader     = currentFile.Find(LAME_Identifier);

                    if (QualityPresent)
                    {
                        //Header offset + 8 (XING + flags) + Frames, Bytes and TOC if available
                        currentFile.Seek(XingHeader + 8 + 4 * (FramesPresent ? 1 : 0) + 4 * (BytesPresent ? 1 : 0) + 100 * (TOCPresent ? 1 : 0));
                        ByteVector Quality_data = currentFile.ReadBlock(4);
                        int        VBRQuality   = BitConverter.ToInt32(Quality_data.ToArray().Reverse().ToArray(), 0);
                        bVBR = true;
                    }
                    currentFile.Mode = TagLib.File.AccessMode.Closed;

                    //                    if (xing_header.Present)
                    //                        return false;
                    //                    var vector = new TagLib.ByteVector();
                    //                    TagLib.ByteVector xing = header.;
                    /* CODE HERE */

                    /*                    TagLib.File ref(fileName);
                     *                  TagLib.Mpeg.File *file = dynamic_cast<TagLib.Mpeg.File *>(ref file());
                     *
                     *                  if(!file)
                     *                      return;
                     *
                     *                  TagLib.Mpeg.Properties *properties = file->audioProperties();
                     *                  const TagLib::MPEG::XingHeader *xingHeader = properties->xingHeader();
                     *
                     *                  if(!xingHeader)
                     *                      return;
                     */
                }

                if (header.VBRIHeader.Present)
                {
                    /* CODE HERE */
                }
            }
            return(bVBR);
        }