– Jens Alfke, quoted from the Core Audio Mailing List “"Easy" and "CoreAudio" can't be used in the same sentence. :P CoreAudio is very powerful, very complex, and under-documented. Be prepared for a steep learning curve, APIs with millions of tiny little pieces, and puzzling things out from sample code rather than reading high-level documentation.”
– Q “If you can't take a little bloody nose, maybe you ought to go back home and crawl under your bed. It's not safe out here. It's wondrous, with treasures to satiate desires both subtle and gross. But it's not for the timid.”
What is AV Foundation? AV Foundation is one of several frameworks that you can use to play and create time-based audiovisual media. It provides an Objective-C interface you use to work on a detailed level with time-based audiovisual data.
Advantages of AV Foundation Built-in interruption handling Written in Objective-C Optimized for the iOS ecosystem Now powerful enough to do much of what Core Audio does
AVAudioSession AVAudioSession is a singleton object that comes included into your projects regardless of whether you create one or not. AVAudioSession manages all of the other AV Audio objects.
AVAudioSession Activate/Deactivate the audio session Set the audio session category Configure audio settings Handle audio route changes and react to audio events
Audio Session Default Behavior Playback Enabled, Recording Disabled “Silent” switch mutes your sound When the phone sleeps your sound stops When your audio starts other audio, like iTunes, stops playing.
AV Audio Session Category MultiRoute Used to send sound to more than one output (disk, headphones, speaker, etc…) FYI: The default audio route is to the phone receiver, you can override this to go to the speaker on the bottom of the phone
AV Audio Session Category Playback Is NOT silenced by the mute switch Does not allow other audio by default, but you can override this behavior Output only
AV Audio Session Category Record Input only, so it is not affected by the mute switch and it does not allow audio from other apps I find this to be limiting and would recommend the next category instead.
AV Audio Session Category Play and Record Is NOT silenced by the mute switch Does not allow other audio by default, but you can override this behavior Both Input and Output
Quiz Time!! Scenario 1: You are writing an audio book app. You need to make sure the audio keeps playing when the device falls asleep. What category should you use?
Quiz Time! Scenario 3: You write a first-person shooter game that uses OpenAL- based sound effects. You also provide a background soundtrack but include an option for the user to turn it off. What session type do you use?
How to Choose Your Audio Category Think about the primary purpose for audio in your app Is your audio essential or peripheral? How likely is it that other audio will be playing when your app is launched?