Created
June 25, 2012 12:38
-
-
Save edwardinubuntu/2988342 to your computer and use it in GitHub Desktop.
audioRouteChangeListenerCallback
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void audioRouteChangeListenerCallback ( | |
void *inUserData, | |
AudioSessionPropertyID inPropertyID, | |
UInt32 inPropertyValueSize, | |
const void *inPropertyValue | |
) { | |
// ensure that this callback was invoked for a route change | |
if (inPropertyID != kAudioSessionProperty_AudioRouteChange) return; | |
if ([inUserData isKindOfClass:[IVAudioPlayerController class]]) { | |
IVAudioPlayerController *controller = (IVAudioPlayerController *) inUserData; | |
// if application sound is not playing, there's nothing to do, so return. | |
if (controller.audioStreamer.state == AS_STOPPED ) { | |
TTDPRINT(@"Audio route change while application audio is stopped."); | |
return; | |
} else { | |
// Determines the reason for the route change, to ensure that it is not | |
// because of a category change. | |
CFDictionaryRef routeChangeDictionary = inPropertyValue; | |
CFNumberRef routeChangeReasonRef = | |
CFDictionaryGetValue ( routeChangeDictionary, CFSTR (kAudioSession_AudioRouteChangeKey_Reason) ); | |
SInt32 routeChangeReason; | |
CFNumberGetValue ( routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason ); | |
// "Old device unavailable" indicates that a headset was unplugged, or that the | |
// device was removed from a dock connector that supports audio output. This is | |
// the recommended test for when to pause audio. | |
if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable) { | |
TTDPRINT(@"Output device removed, so application audio was paused."); | |
[controller pause]; | |
} else { | |
TTDPRINT(@"A route change occurred that does not require pausing of application audio."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks! found it useful