This simple module routes audio depending on device availability using the following priorities: bluetooth, wired headset, speaker.
It also notifies interested listeners of audio change events (optional).
The only requirement to use this module is an ARC-based iOS 6+ project.
AudioSessionManager is a singleton which can be initialized with a single statement:
// Initialize the audio session...
[[AudioSessionManager sharedInstance] startAndPostNotifications:YES];
Two notifications are posted by this library if enabled:
- kAudioSessionManagerDevicesAvailableChangedNotification - the list of devices (returned by the
availableAudioDevices
property) has changed - kAudioSessionManagerAudioDeviceChangedNotification - the current audio device (returned by the
audioDevice
property) has changed
NSLog(@"audioRoute is %@", [AudioSessionManager sharedInstance].audioRoute);
Configuring the device for input:
if (![[AudioSessionManager sharedInstance] changeMode:kAudioSessionManagerMode_Record]) {
// .... handle error ...
}
and output:
if (![[AudioSessionManager sharedInstance] changeMode:kAudioSessionManagerMode_Playback]) {
// .... handle error ...
}