User guide

Adding Volume and Route Control
Use the MPVolumeView class to present volume and routing control for your app. The volume view provides
a slider to control the volume from inside your app and a button for choosing the output audio route. Apple
recommends using the MPVolumeView route picker over AVAudioSessionPortOverride when routing
audio to the built-in speaker. See MPVolumeView Class Reference .
Responding to Remote Control Events
Remote control events let users control an apps multimedia. If your app plays audio or video content, you
might want it to respond to remote control events that originate from either transport controls or external
accessories. iOS converts commands in UIEvent objects and delivers the events to the app. The app sends
them to the first responder and, if the first responder doesn’t handle them, they travel up the responder chain.
Your app must be the “Now Playing” app and currently playing audio before it can respond to events. See
Remote Control Events and MPNowPlayingInfoCenter Class Reference.
Activating and Deactivating Your Audio Session
The system activates your audio session on app launch. Even so, Apple recommends that you explicitly activate
your session—typically as part of your apps viewDidLoad method, and set preferred hardware values prior
to activating your audio session. See Setting Preferred Hardware Values (page 33) for a code example. This
gives you an opportunity to test whether activation succeeded. However, if your app has a play/pause UI
element, write your code so that the user must press play before the session is activated. Likewise, when
changing your audio sessions active/inactive state, check to ensure that the call is successful. Write your code
to gracefully handle the systems refusal to activate your session.
The system deactivates your audio session for a Clock or Calendar alarm or incoming phone call. When the
user dismisses the alarm, or chooses to ignore a phone call, the system allows your session to become active
again. Whether to reactivate a session at the end of an interruption depends on the app type, as described in
Audio Guidelines By App Type (page 43).
Listing 1-1 shows how to activate your audio session.
Listing 1-1 Activating an audio session using the AV Foundation framework
NSError *activationError = nil;
BOOL success = [[AVAudioSession sharedInstance] setActive: YES error:
&activationError];
Defining an Audio Session
Adding Volume and Route Control
2014-09-17 | Copyright © 2014 Apple Inc. All Rights Reserved.
15