O'Reilly logo

Programming iOS 10 by Matt Neuburg

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 14. Audio

iOS provides various means and technologies for allowing your app to produce, record, and process sound. The topic is a large one, so this chapter can only introduce it; I’ll concentrate on basic sound production. You’ll want to read Apple’s Multimedia Programming Guide and Core Audio Overview.

None of the classes discussed in this chapter provides any interface within your app for allowing the user to stop and start playback of sound (transport control). If you want transport interface, here are some options:

  • You can create your own interface.

  • You can associate the built-in “remote control” buttons with your application, as I’ll explain in this chapter.

  • A web view (Chapter 11) supports the HTML5 <audio> tag; this can be a simple, lightweight way to play audio and to allow the user to control playback (including use of AirPlay).

  • You could treat the sound as a movie and use the interface-providing classes that I’ll discuss in Chapter 15; this can also be a good way to play a sound file located remotely over the Internet.

System Sounds

The simplest form of sound is system sound, which is the iOS equivalent of the basic computer “beep.” This is implemented through System Sound Services, part of the Audio Toolbox framework; you’ll need to import AudioToolbox.

The API for playing a system sound changed starting in iOS 9. I’ll show you the old code first (it still works, and has not yet been deprecated); then I’ll demonstrate the new code. The old code involves ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required