Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AV Foundation Cocoa Conf Chicago 2014

AV Foundation Cocoa Conf Chicago 2014

These are the slides from my talk about AV Foundation from Cocoa Conf Chicago 2014

Janie Clayton-Hasz

March 07, 2014

More Decks by Janie Clayton-Hasz

Other Decks in Programming


  1. – 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.”
  2. – 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.”
  3. Here is how to add Sound to your app in

    less than two minutes (which I found out by accident at my last talk…)
  4. So, that’s cool, but it’s kind of limited, isn’t it???

    ! Also, didn’t you promise me there would be no C??
  5. 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.
  6. 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
  7. 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.
  8. AVAudioSession Activate/Deactivate the audio session Set the audio session category

    Configure audio settings Handle audio route changes and react to audio events
  9. 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.
  10. When Can I Ignore the Audio Session? If you are

    using System Sound Services or UIKit playInputClick If you do not use sound at all
  11. AV Audio Session Category Audio Processing No input or output

    Processes audio offline Only really going to be used in a specialized audio app
  12. 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
  13. AV Audio Session Category Ambient Silenced by the mute switch

    Allows audio mixing from other apps, like iTunes Output only
  14. AV Audio Session Category Solo Ambient Silenced by the mute

    switch Does NOT allow audio mixing from other apps Output Only
  15. 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
  16. 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.
  17. 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
  18. AVAudioRecorder Delegate Does NOT allow phone calls to go through,

    so there is no error handling for phone calls.
  19. 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?
  20. Quiz Time! Scenario 2: You are building an app.Net client

    and you want to add a sound effect when the user publishes a post.
  21. 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?
  22. 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?