まず、あなたはそれを初期化するときにオプションAVAudioSessionCategoryOptionMixWithOthers
を設定する必要があります:
NSError *sessionError = NULL;
BOOL success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers
error:&sessionError];
if(!success) {
NSLog(@"Error setting category Audio Session: %@", [sessionError localizedDescription]);
}
中断処理するために(コール、アラーム、など。)、あなたは、必要に応じてAVAudioSession
の有効化/無効化を処理することができますNSNotificationCenter
の中断のためのオブザーバを設定する必要があります。
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleAudioSessionInterruption:)
name:AVAudioSessionInterruptionNotification
object:[AVAudioSession sharedInstance]];
NSNotification意志カーy中断のタイプとキー:
- (void)handleAudioSessionInterruption:(NSNotification*)notification {
NSNumber *interruptionType = [[notification userInfo] objectForKey:AVAudioSessionInterruptionTypeKey];
NSNumber *interruptionOption = [[notification userInfo] objectForKey:AVAudioSessionInterruptionOptionKey];
switch (interruptionType.unsignedIntegerValue) {
case AVAudioSessionInterruptionTypeBegan:{
// • Audio has stopped, already inactive
// • Change state of UI, etc., to reflect non-playing state
NSLog(@"AVAudioSessionInterruptionTypeBegan");
} break;
case AVAudioSessionInterruptionTypeEnded:{
// • Make session active
// • Update user interface
// • AVAudioSessionInterruptionOptionShouldResume option
NSLog(@"AVAudioSessionInterruptionTypeEnded");
if (interruptionOption.unsignedIntegerValue == AVAudioSessionInterruptionOptionShouldResume) {
// Here you should continue playback.
}
} break;
default:
break;
}
}
すばらしい答え!しかし残念ながら問題を解決しませんでした。 AVAudioSession.mm:692: - [AVAudioSession setActive:withOptions:error:]:I/Oを実行しているオーディオセッションを無効にします。オーディオセッションを無効にする前に、すべてのI/Oを停止または一時停止する必要があります。 :AVAudioSession.mm:692: - [AVAudioSession setActive:withOptions:error:]:I/Oを実行しているオーディオセッションを非アクティブにします。オーディオセッションを無効にする前に、すべてのI/Oを停止または一時停止する必要があります。 – saurabh2810
@ saurabh2810上記の例は、他のアプリケーションからの割り込みを処理するためのものです。 SAMEアプリケーションの他の部分がAVを使用しているため、実行中のI/Oエラーが発生しています。あなたのクラスをチェックするか、ハイブリッドであればあなたのプラグインが競合するかもしれません。 –