IOS Audio Recording, How to Check if Mic / Playback is Busy Before Taking Mic

有些话、适合烂在心里 提交于 2019-12-05 10:40:23

问题


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.


回答1:


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"



来源:https://stackoverflow.com/questions/9101190/ios-audio-recording-how-to-check-if-mic-playback-is-busy-before-taking-mic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!