Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Camera Freeze when open app while call is running

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

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];

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)).

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. enter image description here enter image description here

like image 537
Surjeet Singh Avatar asked Mar 07 '16 08:03

Surjeet Singh


People also ask

Why does my camera freeze when I try to take a picture?

Camera freeze happens when the device gets stuck on a screen momentarily while trying to take a picture, sometimes leading to a restart. It can be caused by several things, including corrupted software or SD card, a camera glitch, overheating, or moisture damage.

How do I unfreeze my iPhone camera?

Here's how to do it. Step 1: Press and hold the Sleep/Wake or Power button until the “Slide to Power Off” slider appears. Step 2: Slide to turn off the iPhone. Step 3: Wait at least 30 seconds and press and hold the power button again until you see the Apple Logo and the device restarts.

Why does my iPhone 13 camera freeze up?

Sometimes, the camera crashes where there's not enough storage to save the pictures or videos in. The iPhone storage statistics can be found under General. Try to delete some of your files or uninstall some apps you don't use anymore if necessary.


1 Answers

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

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)

like image 80
Cbas Avatar answered Oct 17 '22 04:10

Cbas