Search code examples
c#mp3taglib-sharp

How to read XingHeaders and VBRIHeaders from MP3 files using TagLib-Sharp


I need to extract the information stored in the Xing and Fraunhofer VBRI headers of MP3 files using TagLib-Sharp.

I've searched around the web for an example, looked at the source code, but it's not obvious how to use the XingHeader and VBRIHeader classes. They don't look to be part of the File/AudioFile properties for MPEG.

The constructor needs a ByteVector class which is defined in the TagLib namespace.

Can anybody provide an example of using the XingHeader and VBRIHeader classes? Any help would be greatly appreciated.


Solution

  • Something like the following should work:

    foreach(ICodec codec in file.Properties.Codecs) {
        Mpeg.AudioHeader header = (Mpeg.AudioHeader) codec;
        if(header == null)
            return;
    
        if(header.XingHeader != Mpeg.XingHeader.Unknown) {
            /* CODE HERE */
        }
    
        if(header.VBRIHeader != VBRIHeader.Unknown) {
            /* CODE HERE */
        }
    }