Reputation: 65
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?
Upvotes: 4
Views: 1865
Reputation: 11156
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.
Upvotes: 2