Chapter 14. Audio
iOS provides various means and technologies for allowing your app to produce and input 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 user interface within your application for allowing the user to stop and start playback of sound. You can create your own such interface, and I’ll discuss how you can associate the “remote control” buttons with your application. Also, a web view (Chapter 11) supports the HTML 5
<audio> tag; this can be a simple, lightweight way to play audio and to allow the user to control playback. (By default, a web view even allows use of AirPlay.) Alternatively, you could treat the sound as a movie and use the MPMoviePlayerController class discussed in Chapter 15; this can also be a good way to play a sound file located remotely over the Internet.
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. You’ll be calling one of two C functions, which behave very similarly to one another:
- On an iPhone, may also vibrate the device, depending on the user’s settings.
- On an iPhone, there won’t be an accompanying ...