- iOSアプリケーションは、音声割り込み処理を適切に行う必要があります。
プログラム解説:基本再生 では、音声割り込み処理を AtomUtilIOS_AudioSessionNotificationObserverクラスのinterruptionHandler:メソッドに実装しています。
また、interruptionHandler:メソッドを criadx2le::audioSessionInitialize 関数内でデフォルトの NSNotificationCenter に AVAudioSessionInterruptionNotification に対するオブザーバを登録しています。
- 注意:
- iOS6より前のOSではAVAudioSessionではなく、AudioSessionのAPIで対応する必要があります。
AtomUtilIOS_AudioSessionNotificationObserverクラスのinterruptionHandler:メソッド
- (void)interruptionHandler: (NSNotification*)notification
{
int value = [[notification.userInfo valueForKey: AVAudioSessionInterruptionTypeKey] intValue];
switch (value) {
case AVAudioSessionInterruptionTypeBegan:
criAtomEx_StopSound_IOS();
audioSessionSetActive(NO);
break;
case AVAudioSessionInterruptionTypeEnded:
default:
audioSessionSetActive(YES);
criAtomEx_StartSound_IOS();
break;
}
}
criadx2le::audioSessionInitialize 関数内
NSNotificationCenter* notification_center = [NSNotificationCenter defaultCenter];
AVAudioSession* audio_session = [AVAudioSession sharedInstance];
[notification_center
addObserver: audiosession_notification_observer
selector: @selector(interruptionHandler:)
name: AVAudioSessionInterruptionNotification
object: audio_session
];