2016-05-09 2 views
0

Quickbloxを使用してビデオ通話を受信できる状態で、スピーカーで曲を再生したい。Avaudiosessionの非アクティブ化を停止するにはどうすればよいですか?

私のオーディオレートが狂っています。 さらに大きな問題は、コールが終了したときにquickbloxフレームワークがオーディオ・セッションを非アクティブ化状態に設定することです。すなわち [Avaudiosession sharedInstance] setActive:NO ....

これをどのようにして止めるのですか?

また、上記のシナリオを処理できる方法がありますか?

私は1ヶ月間googleを読んでいますが、まだ適切な回答やガイドラインが見つかりませんでした。 誰もこの問題で私を助けることができますか?/ ?? AVAudioSessionは、他のAVAudioSessionsと連携できるようにする

答えて

1

まず、あなたはそれを初期化するときにオプション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; 
    } 
} 
+0

すばらしい答え!しかし残念ながら問題を解決しませんでした。 AVAudioSession.mm:692: - [AVAudioSession setActive:withOptions:error:]:I/Oを実行しているオーディオセッションを無効にします。オーディオセッションを無効にする前に、すべてのI/Oを停止または一時停止する必要があります。 :AVAudioSession.mm:692: - [AVAudioSession setActive:withOptions:error:]:I/Oを実行しているオーディオセッションを非アクティブにします。オーディオセッションを無効にする前に、すべてのI/Oを停止または一時停止する必要があります。 – saurabh2810

+0

@ saurabh2810上記の例は、他のアプリケーションからの割り込みを処理するためのものです。 SAMEアプリケーションの他の部分がAVを使用しているため、実行中のI/Oエラーが発生しています。あなたのクラスをチェックするか、ハイブリッドであればあなたのプラグインが競合するかもしれません。 –

関連する問題