From 84fd73630af22557c516afd3b2c6ad0e31534097 Mon Sep 17 00:00:00 2001 From: Justin Hawkwood Date: Fri, 3 Apr 2015 15:57:47 -0700 Subject: [PATCH] Fix iOS 5.1.1 crash caused by interruptionHandler checks OS version and sets handling based on what is available. --- cocos/audio/apple/AudioEngine-inl.mm | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/cocos/audio/apple/AudioEngine-inl.mm b/cocos/audio/apple/AudioEngine-inl.mm index e01b99586e..0f9bc4df00 100644 --- a/cocos/audio/apple/AudioEngine-inl.mm +++ b/cocos/audio/apple/AudioEngine-inl.mm @@ -141,11 +141,31 @@ namespace cocos2d { @implementation AudioEngineSessionHandler +void AudioEngineInterruptionListenerCallback(void* user_data, UInt32 interruption_state) +{ + if (kAudioSessionBeginInterruption == interruption_state) + { + alcMakeContextCurrent(nullptr); + } + else if (kAudioSessionEndInterruption == interruption_state) + { + OSStatus result = AudioSessionSetActive(true); + if (result) NSLog(@"Error setting audio session active! %d\n", result); + + alcMakeContextCurrent(s_ALContext); + } +} + -(id) init { if (self == [super init]) { + if ([[[UIDevice currentDevice] systemVersion] intValue] > 5) { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleInterruption:) name:AVAudioSessionInterruptionNotification object:[AVAudioSession sharedInstance]]; + } + else { + AudioSessionInitialize(NULL, NULL, AudioEngineInterruptionListenerCallback, self); + } } return self; }