2016-03-07 47 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

相关问题