views:

513

answers:

2

I need to get bitrate information from audio files, for some reason AudioFileGetProperty function with kAudioFilePropertyBitRate constant always returns 0 for me. The same with kAudioFilePropertyInfoDictionary, the resulting dictionary doesnt contain bitrate info. I would try to manualy get this from raw data in case of mp3, but I need to support different file formats such as m4a and others. Is there any other way to do this?

+2  A: 

If you're dealing with a file, you could always try using the Spotlight metadata API. For instance, assuming you have the path to your audio file as an NSString or CFStringRef called 'path':

MDItemRef item = MDItemCreate( kCFAllocatorDefault, path );
CFNumberRef audioBitrate = MDItemCopyAttribute( item, kMDItemAudioBitrate );
CFNumberRef totalBitrate = MDItemCopyAttribute( item, kMDItemTotalBitrate );
CFRelease( item );

It's not ideal, but might at least provide you with some more background information to suggest why the other API isn't working.

The only other thing I can think of: kAudioFilePropertyBitRate is only defined in OS X 10.5. If you're running on 10.4 or earlier, your code will still run, but the AudioFile framework won't know about the bitrate property at all, and would therefore likely return zero.

Jim Dovey
Thanks for info, the Spotlight api was my last resort, just wanted make sure if there isn't any other audio api that can do this. Im running on 10.5 which is also minspec
stackzerad
A: 

0 is a common indication of a file with a variable bit-rate (compressed).

Justin