title: Determine if an audio file is VBR
body: <p>I'm trying to determine whether an audio file uses VBR or not in a Cocoa app (OS X 10.8+).</p>
  
  <p>AVFoundation doesn't seem to be able to answer the question at all, and AudioToolbox is lying to me.</p>
  
  <p>The code below adamantly claims that any mp3 file I throw at it is VBR; even for files where I know that isn't the case (cross-checked with <a href="http://mediaarea.net/" rel="nofollow" title="MediaInfo Homepage">MediaInfo</a>)</p>
  
  <pre><code>OSStatus result = noErr;
  UInt32 size;
  
  AudioFileID audioFile;
  AudioStreamBasicDescription audioFormat;
  AudioFormatPropertyID vbrInfo;
  
  // Open audio file.
  result = AudioFileOpenURL( (__bridge CFURLRef)originalURL, kAudioFileReadPermission, 0, &amp;audioFile );
  if( result != noErr )
  {
      NSLog( @"Error in AudioFileOpenURL: %d", (int)result );
      return;
  }
  
  // Get data format
  size = sizeof( audioFormat );
  result = AudioFileGetProperty( audioFile, kAudioFilePropertyDataFormat, &amp;size, &amp;audioFormat );
  if( result != noErr )
  {
      NSLog( @"Error in AudioFileGetProperty: %d", (int)result );
      return;
  }
  
  // Get vbr info
  size = sizeof( vbrInfo );
  result = AudioFormatGetProperty( kAudioFormatProperty_FormatIsVBR, sizeof(audioFormat), &amp;audioFormat, &amp;size, &amp;vbrInfo);
  
  if( result != noErr )
  {
      NSLog( @"Error getting vbr info: %d", (int)result );
      return;
  }
  
  NSLog(@"%@ is VBR: %d", originalURL.lastPathComponent, vbrInfo);
  </code></pre>
  
  <p>Why is it lying? What am I doing wrong?</p>
  
  <p><strong>How can I realiably determine the VBR-iness of an audio file in a Cocoa Application?</strong></p>
  
  <p>VBR and CBR sample files can be obtained <a href="http://nigelcoldwell.co.uk/audio/" rel="nofollow">here</a> (not my page).</p>