2016-03-07 15 views
7

AVCaptureSessionを使用してカメラを作成しました。私は写真とビデオの両方の記録モードのためにそれを設定しましたカメラ呼び出しが実行中に開いているアプリケーションをフリーズする

カメラとアプリケーションは正常に動作しています。また、私はバックグラウンドミュージックの再生を許可(iPhoneのミュージックアプリを使用しているユーザーが音楽を再生している場合)オープンカメラまたは録画ビデオ中。それは正常に動作しています。 (添付画像2)

は、私は私がホームボタンとオープンアプリをタップして、コールは、電話の画面を最小化する受信した場合、バックグラウンドミュージックは今、このコード

AVAudioSession *session1 = [AVAudioSession sharedInstance]; 
    [session1 setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth error:nil]; 
    [session1 setActive:YES error:nil]; 
    [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; 

の助けを借りて遊ぶ許可しました画像/録画ビデオをキャプチャするためにカメラの画面を開こうとすると、画像は開きますが、画像(添付画像(1))でフリーズします。

私の要件は、電話で画像/録画ビデオをキャプチャしたいのです。私は別のアプリを探して、Snapchatは同じをやっていて、私は電話中にビデオを録画することができます。

私はこれをどのように達成することができますか教えてください。 あなたはセッションが中断されている間AVCaptureSessionWasInterruptedNotificationAVCaptureSessionInterruptionEndedNotificationコールバックを使用して、オーディオキャプチャを切断する必要がenter image description hereenter image description here

+0

いいえ、まだ解決策を探しています。 – Surjeet

+0

私は私のプロジェクトで同じ問題を抱えています。どちらの場合も同じコードが実行されますが、カメラは何とか開いていません。これまでのアイデアや解決策はありますか? – virusss8

答えて

2

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionWasInterrupted:) name:AVCaptureSessionWasInterruptedNotification object:self.session]; 
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionInterruptionEnded:) name:AVCaptureSessionInterruptionEndedNotification object:self.session]; 
// note that self.session is an AVCaptureSession 

-

- (void)sessionWasInterrupted:(NSNotification *)notification { 
    NSLog(@"session was interrupted"); 

    AVCaptureDevice *device = [[self audioInput] device]; 
    if ([device hasMediaType:AVMediaTypeAudio]) { 
    [[self session] removeInput:[self audioInput]]; 
    [self setAudioInput:nil]; 
    } 
} 

- (void)sessionInterruptionEnded:(NSNotification *)notification { 
    NSLog(@"session interuption ended"); 
} 
// note that [self audioInput] is a getter for an AVCaptureDeviceInput 

これは、カメラの動作を続行することができます静止画/無音映像を記録することができます。

これで、通話が終了した後にオーディオを再接続する方法を教えてください。あなたがそれを見つけた場合はお知らせください:Callback when phone call ends? (to resume AVCaptureSession)

+0

ありがとうございます これは私の大きな問題を解決しています。 – Anita

関連する問題