1. A path to an audio file added in Resource Folder in project workspace.
2. Convert the string to NSURL as Core Audio API's work with NSURL.
3. Audio file objects are referred by AudioFileID type, so you must declare a reference as a local variable.
4. Almost all Core Audio functions return success or failure as their signal value, the type of that signal is OSStatus. Any status other than noErr (i.e 0) signals an error. You must check this signal value on every Core Audio api call, because it makes no sense to check the last API call, and leaving all other checks. Since there can be error at any API call. So subsequent API calls have no meaning in it.
5. This is the first Core Audio function call: AudioFileOpenURL. There are four parameters in this function, A CFURLRef, a permission flag, a file type hint, and a pointer to receive the created AudioFileID Object. Type cast the NSURL to CFURLRef by using __bridge keyword to match the first parameter. Pass a file read permission constant to read the file. Pass 0 for the hint as Core Audio will figure it out. For the last parameter, pass the & "address of" operator to provide a pointer to receive the AudioFileID object.
6. If AudioFileOpenURL returns an error, the code will exit and will display the error.
7. To get the file metadata, we need to use the property kAudioFilePropertyInfoDictionary. But that API call requires allocating memory first. So, we need to declare a local variable to receive the size we'll need to allocate.
8. To get the size, we need to call AudioFileGetPropertyInfo function, it takes four parameters, an AudioFileID object, the property about the information needed, a pointer to receive the size, and a pointer to a flag variable indicating whether the property is writable (as we don't care, pass it 0).
9. If AudioFileGetPropertyInfo fails, program terminates.
10. To get the meta data information we need a variable of type CFDictionaryRef, as kAudioFilePropertyInfoDictionary results in a dictionary.
11. Call the function AudioFileGetProperty to get the meta data information. There are 4 parameters to be passed in the function, an AudioFileID object, the property constant, a pointer to the size of the data that is about to receive, and a pointer to receive the value.
12. Again, check the return value and fail if it’s anything other than noErr.
13. Get the string representation of a dictionary by passing "%@" as the format specifier for string.
14. Release the Core foundation object by using CFRelease function.
15. The AudioFileID also needs to be cleaned up. It is not a Core Foundation object so we cannot use CFRelease() function for that. To clean up AudioFileID object we need to use AudioFileClose() function.
16. AudioFileClose() is another API call, so continue to check the return code.
So, thats the code to get the meta data of an audio file. Opening a File, Allocating a buffer for metadata, and getting the metadata.