2

I want to be able to detect if microphone is available for recording a video, and if the user is on a phone call microphone isn't available. What is the best way to detect microphone availability taking into account phone calls. This is the code I have for adding microphone and it doesn't detect that a microphone is unavailable during phone call

self.session = [[AVCaptureSession alloc] init];
audioDevice = [[AVCaptureDevice devicesWithMediaType:AVMediaTypeAudio] firstObject];
audioDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:audioDevice error:&error];
if ([self.session canAddInput:audioDeviceInput])
{
    [self.session addInput:audioDeviceInput];
}
kevin
  • 4,177
  • 10
  • 32
  • 33

1 Answers1

0

If a phone call is in session, or if some other app is playing audio, you can detect this via AVAudioSession:

BOOL audioInUse = [AVAudioSession sharedInstance].isOtherAudioPlaying;
Mark Semsel
  • 7,125
  • 3
  • 29
  • 27