【问题标题】:Camera Freeze when open app while call is running通话时打开应用程序时相机冻结
【发布时间】:2016-06-20 18:13:08
【问题描述】:

我创建了一个使用 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 也在做同样的事情,我可以在通话时录制视频。

请帮助我,我怎样才能做到这一点。

【问题讨论】:

  • 否,仍在寻找解决方案。
  • 我的项目中有同样的问题。在这两种情况下都执行相同的代码,但不知何故未打开相机。到目前为止,您有什么想法或解决方案吗?
  • @Surjeet,你有没有得到我面临同样的解决方案,问题请帮忙!

标签: ios objective-c avcapturesession avaudiosession


【解决方案1】:

您需要使用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

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

现在至于如何在通话结束后重新连接音频.. 如果你弄清楚了,请告诉我,从 iOS 10 开始似乎是不可能的:Callback when phone call ends? (to resume AVCaptureSession)

【讨论】:

    猜你喜欢
    • 2022-10-05
    • 1970-01-01
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多