Working with Audio on the iPad
Cars make noise, and a ’59 Cadillac certainly doesn’t disappoint in that respect. So in this section, I show you how to add some sound to the RoadTrip app so that everyone can hear your car coming down the road.
More specifically, I discuss using two different ways iOS has for implementing audio. One is an instance of the AVAudioPlayer
class — called, appropriately enough, an audio player — which provides playback of audio data from a file or memory. You use this class unless you’re playing audio captured from a network stream or in need of very low I/O latency (lag time). The AVAudioPlayer
class offers quite a lot of functionality, including playing sounds of any duration, looping sounds, playing multiple sounds simultaneously, and having one sound per audio player with precise synchronization among all the players in use. It also controls relative playback level, stereo positioning, and playback rate for each sound you’re playing.
The AVAudioPlayer
class lets you play sound in any audio format available in iOS. You implement a delegate to handle interruptions (such as an incoming SMS message) and to update the user interface when a sound has finished playing. The delegate methods to use are described in the AVAudioPlayerDelegate
Protocol Reference (which you can access in the Organizer window as I explain in Chapter 7).
The second way to play sound is by using System Sound Services, which provides a way to play short sounds and make the device vibrate. ...
Get iPad Application Development For Dummies, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.