2016-03-07 92 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]; 

的幫助起到現在,如果我收到通過點擊Home鍵和開放的應用程序的調用,儘量減少手機通話屏幕並想打開相機屏幕來捕捉圖像/錄製視頻,然後打開它並凍結圖像(附圖(1))。

現在我的要求是,我想在拍電話時拍攝圖像/錄製視頻。我尋找另一個應用程序,並且Snapchat正在做同樣的,並且我能夠在我打電話時錄製視頻。

請幫助我,我該如何做到這一點。 enter image description hereenter image description here

+0

不,仍在尋找解決方案。 – Surjeet

+0

我的項目中有同樣的問題。在這兩種情況下執行相同的代碼,但相機不知何故未打開。目前爲止,您有任何想法或解決方案嗎? – virusss8

回答

2

您需要使用AVCaptureSessionWasInterruptedNotificationAVCaptureSessionInterruptionEndedNotification回調和斷開音頻捕獲,同時會話被中斷:

[[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

非常感謝你 這是解決我bigg問題。 – Anita

相關問題