O'Reilly logo

Programming iOS 4 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 27. Audio

iOS provides various means and technologies for allowing your app to produce sound (and even to input it). The topic is a large one, so this chapter can only introduce it. You’ll want to read Apple’s Multimedia Programming Guide and Core Audio Overview.

Note

None of the classes discussed in this chapter provide any user interface within your application for allowing the user to stop and start playback of sound (though you can create your own interface and use it with them). However, a web view (Chapter 24) supports the HTML 5 <audio> tag; this can be a simple, lightweight way to play audio and to allow the user to control playback. Or treat the sound as a movie and use the MPMoviePlayerController class discussed in Chapter 28; 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; you’ll need to import <AudioToolbox/AudioToolbox.h> and link to AudioToolbox.framework. You’ll be calling one of two C functions, which behave very similarly to one another:

AudioServicesPlayAlertSound
Plays a sound and, on an iPhone, may also vibrate the device, depending on the user’s settings. On the original iPod touch, plays only a built-in alert sound.
AudioServicesPlaySystemSound
Plays a short sound of your choice. On an iPhone, there won’t be an accompanying vibration, but you can specifically ...

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