相机冻结时打开的应用程序,而电话正在运行

用AVCaptureSession创build了一个相机 。 我已经configuration了照片和录像模式

相机和应用程序运行良好。 此外,我允许背景音乐播放 (如果用户使用iPhone中的音乐应用程序播放歌曲),而打开相机或录制video。 它也工作正常。 (附图2)

我允许背景音乐播放与此代码的帮助

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

现在,如果我接到电话 ,请点击主页button并打开应用程序,以最小化电话呼叫屏幕,并打开相机屏幕捕捉图像/录制video,打开但冻结图像(附图(1))。

现在我的要求是,我想要通过电话拍摄图像/录制video。 我寻找另一个应用程序,和Snapchat是一样的 ,我可以录制video,而我在电话。

请帮助我,我怎么能做到这一点。 在这里输入图像说明 在这里输入图像说明

您需要使用AVCaptureSessionWasInterruptedNotificationAVCaptureSessionInterruptionEndedNotificationcallback函数,并在会话中断时断开audio捕获:

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

这将允许相机继续运行,并允许它录制静止/无声的video

现在至于如何重新连接通话结束后的audio..让我知道,如果你弄明白了: 回拨时,电话结束? (恢复AVCaptureSession)