在呼叫正在运行时打开应用程序时相机冻结 [英] Camera Freeze when open app while call is running

查看:162
本文介绍了在呼叫正在运行时打开应用程序时相机冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AVCaptureSession 创建了相机。我为照片和视频录制模式配置了

I have created a camera using AVCaptureSession. I have configured that for both Photo and Video recording modes.

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

Camera and App is running fine. Also I allowed background music play (If user play song using Music App in iPhone) while open camera or recording video. It is also working fine. (Attached image 2)

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

I allowed background Music play with the help of this code

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

现在,如果我接到电话,请点按最小化电话屏幕主页按钮和打开的应用程序,并希望打开相机屏幕捕获图像/录制视频,它打开但冻结图像(附加图像(1))。

Now if i receive a call, minimize phone call screen by tapping on Home button and open app and want to open camera screen to capture image / record video, It opens but freeze with a image (Attached image(1)).

现在我的要求是,我想在通话时捕捉图像/录制视频。我找了另外一个应用程序, Snapchat正在做同样的,我可以在通话时录制视频。

Now my requirement is, i want to capture image / record video while on phone call. I looked for another apps, and Snapchat is doing same, and i am able to record video while i am on call.

请帮助我,我怎样才能实现这一目标。

please help me, how can i achieve this.

推荐答案

您需要使用 AVCaptureSessionWasInterruptedNotification AVCaptureSessionInterruptionEndedNotification 回调并在会话中断时断开音频捕获:

You need to use the AVCaptureSessionWasInterruptedNotification and AVCaptureSessionInterruptionEndedNotification callbacks and disconnect the audio capture while the session is interrupted:

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

这将允许相机继续运行并允许它捕捉静止/静音视频

This will allow the camera to continue running and allows it to capture stills / silent video

现在关于如何在通话结束后重新连接音频..让我知道你是否弄明白,从iOS 10开始看似乎不可能:回电时电话结束了吗? (恢复AVCaptureSession)

Now as for how to reconnect the audio after the call ends.. let me know if you figure it out, seemed impossible as of iOS 10: Callback when phone call ends? (to resume AVCaptureSession)

这篇关于在呼叫正在运行时打开应用程序时相机冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆