0

If anything is playing, recording, how to we check to see if the MIC is available (idle) for recording? Currently using

AVCaptureDevice *audioCaptureDevice      = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeAudio];
AVCaptureSession *captureSession         = [[AVCaptureSession alloc] init];
VCaptureDeviceInput *audioInput          = [AVCaptureDeviceInput deviceInputWithDevice : audioCaptureDevice error:&error];
AVCaptureAudioDataOutput    *audioOutput = [[AVCaptureAudioDataOutput alloc] init];
[captureSession addInput  : audioInput];
[captureSession addOutput : audioOutput];
[captureSession startRunning];

Need to check before grabbing the MIC / Playback from something that is already has it.

ort11
  • 3,359
  • 4
  • 36
  • 69

1 Answers1

6

The mic device can not be busy/access to it can not be locked, even if you call [AVCaptureDevice lockForConfiguration] on a mic device it will not lock it and it is still accessible to the foreground application.

To see if other audio is playing you can check kAudioSessionProperty_OtherAudioIsPlaying e.g.:

UInt32 propertySize, audioIsAlreadyPlaying=0;
propertySize = sizeof(UInt32);
AudioSessionGetProperty(kAudioSessionProperty_OtherAudioIsPlaying, &propertySize, &audioIsAlreadyPlaying);

Additionally on Audio Session Programming Guide it is stated: "There is no programmatic way to ensure that an audio session is never interrupted. The reason is that iOS always gives priority to the phone. iOS also gives high priority to certain alarms and alerts"

valexa
  • 4,462
  • 32
  • 48
  • Will check it out and get back. I saw this in the spec / other code, but looking for mic no playing, but could consider to be for the mic also. Yes on the interruption. I have logged a bug with APPLE on end interruptions not getting called back to the APP properly / all the time (Phone / You Tube, etc). – ort11 Apr 09 '12 at 15:28
  • Using the code above, the final value of audioIsAlreadyPlaying is 0 when audio is playing, but is non-zero when the device's mute switch is active. Strange – Tom Pace Jan 13 '13 at 03:23