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

Be74593ca7b09a1b92ab64586ffe9533?s=128

Janie Clayton-Hasz

March 07, 2014
Tweet

Transcript

  1. All the Audio You Need Beginners Guide to AV Foundation

    Audio
  2. Remedial Core Audio 101

  3. Foundations of Core Audio Audio Queue Audio Session Audio Unit

  4. None
  5. None
  6. – 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.”
  7. – 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.”
  8. So what do we do??

  9. System Sound Services and AVFoundation!!

  10. Here is how to add Sound to your app in

    less than two minutes (which I found out by accident at my last talk…)
  11. Demo

  12. System Sound Services

  13. System Sound Services

  14. System Sound Services

  15. Wait a second, this is supposed to just be about

    AVFoundation!! What gives??
  16. So, that’s cool, but it’s kind of limited, isn’t it???

    ! Also, didn’t you promise me there would be no C??
  17. AV Foundation

  18. 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.
  19. 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
  20. AV Foundation Audio Classes AVAudioSession AVAudioPlayer AVAudioRecorder

  21. 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.
  22. AVAudioSession Activate/Deactivate the audio session Set the audio session category

    Configure audio settings Handle audio route changes and react to audio events
  23. 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.
  24. 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
  25. Audio Session Categories AVAudioSessionCategorySoloAmbient (default) AVAudioSessionCategoryAmbient AVAudioSessionCategoryPlayback AVAudioSessionCategoryRecord

  26. Audio Session Categories AVAudioSessionCategoryPlayAnd Record AVAudioSessionCategoryAudio Processing AVAudioSessionCategoryMultiRoute

  27. AV Audio Session Category Audio Processing No input or output

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

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

    switch Does NOT allow audio mixing from other apps Output Only
  31. Demo

  32. Ambient vs Solo Ambient

  33. 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
  34. AVAudioPlayer Delegate Has built-in methods to handle interruptions from phone

    calls and alerts.
  35. Demo

  36. Ready Player One Demo

  37. Ready Player One Demo

  38. Ready Player One Demo

  39. Ready Player One Demo

  40. Ready Player One Demo

  41. Ready Player One Demo

  42. Ready Player One Demo

  43. 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.
  44. 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
  45. Demo

  46. Recorder Demo

  47. Recorder Demo

  48. Recorder Demo

  49. Recorder Demo

  50. I [insert name here]…

  51. Do solemnly swear…

  52. Never to use my laptop microphone…

  53. For anything I intend for human consumption…

  54. So help me Jobs.

  55. AVAudioRecorder Delegate Does NOT allow phone calls to go through,

    so there is no error handling for phone calls.
  56. 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?
  57. Choices: A: AVAudioSessionCategoryAmbient B: AVAudioSessionCategoryPlayback C: System Sound Services with

    AVAudioSessionCategorySoloAmbient
  58. Quiz Time!! Answer: B AVAudioSessionCategoryPlayback

  59. 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.
  60. Choices: A: AVAudioSessionCategoryAmbient B: AVAudioSessionCategoryPlayback C: System Sound Services with

    AVAudioSessionCategorySoloAmbient
  61. Quiz Time! Answer: C 
 System Sound Services with AVAudioSessionCategorySoloAmbient

  62. 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?
  63. Choices: A: AVAudioSessionCategoryAmbient B: AVAudioSessionCategoryPlayback C: System Sound Services with

    AVAudioSessionCategorySoloAmbient
  64. Quiz Time! Answer: A AVAudioSessionCategoryAmbient

  65. None
  66. 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?
  67. For the More Curious:

  68. In Conclusion

  69. So Now You Know… @RedQueenCoder