IOS录音,如何在麦克风前检查麦克风/播放是否忙碌 [英] IOS Audio Recording, How to Check if Mic / Playback is Busy Before Taking Mic

查看:1203
本文介绍了IOS录音,如何在麦克风前检查麦克风/播放是否忙碌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果正在播放,录制,我们如何检查MIC是否可用(空闲)进行录制?目前正在使用

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

在从已有的MIC / Playback中获取MIC / Playback之前需要检查。

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

推荐答案

即使你调用 [AVCaptureDevice lockForConfiguration],麦克风设备也无法忙/无法锁定它] 在麦克风设备上它不会锁定它,前台应用程序仍然可以访问它。

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.

要查看其他音频是否正在播放,您可以查看 kAudioSessionProperty_OtherAudioIsPlaying 例如:

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

另外音频会话编程指南说明:没有编程方式可以确保音频会话永远不会中断。原因是iOS始终优先考虑手机.iOS也优先考虑某些警报和警报

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"

这篇关于IOS录音,如何在麦克风前检查麦克风/播放是否忙碌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆