Application can listen to Audio route change by observing the AVAudioSessionRouteChangeNotification.
Apple documentation has the below state diagram depicting the over all scenario for this
The below are the actions to be done by the app in order to respond to the audio route changes
1. Implement the methods to be invoked upon the route change
2. Register for the AVAudioSessionRouteChangeNotification notification to respond to the route changes
As an example, the app receives notification when a user unplugs the headset during playback. Following the apple guidelines, the app pauses. The app can then provide a display that prompts the user to continue playing.
When the system sends a route change notification, it provides information such as below.
It contains a userInfo dictionary which contains information on why the route changed and what was the previous route. These info can be retrieved using the dictionary keys AVAudioSessionRouteChangeReasonKey and AVAudioSessionRouteChangePreviousRouteKey.
Below are the reasons for the Audio session route changes
enum {
AVAudioSessionRouteChangeReasonUnknown = 0,
AVAudioSessionRouteChangeReasonNewDeviceAvailable = 1,
AVAudioSessionRouteChangeReasonOldDeviceUnavailable = 2,
AVAudioSessionRouteChangeReasonCategoryChange = 3,
AVAudioSessionRouteChangeReasonOverride = 4,
AVAudioSessionRouteChangeReasonWakeFromSleep = 6,
AVAudioSessionRouteChangeReasonNoSuitableRouteForCategory = 7,
AVAudioSessionRouteChangeReasonRouteConfigurationChange = 8,
};
Application can also get to know the previous route by checking the value for the key AVAudioSessionRouteChangePreviousRouteKey
One reason for route change is AVAudioSessionRouteChangeReasonCategoryChange. Due to this, if application is interested only in headset plug in and plug out, then check the reason for the route change and then process the change accordingly.
References:
-- Living Mobile --: Ios Listening To Audio Route Changes >>>>> Download Now
ReplyDelete>>>>> Download Full
-- Living Mobile --: Ios Listening To Audio Route Changes >>>>> Download LINK
>>>>> Download Now
-- Living Mobile --: Ios Listening To Audio Route Changes >>>>> Download Full
>>>>> Download LINK 7H