简体   繁体   中英

Disabling microphone programmatically

I wonder if there is any way to disable microphone programmatically (to get rid of the red bar in the background)?

I use OpenEars to listen for commands in the app. When I go to the background red bar appears (which is obvious, as microphone is active). The problem is that the microphone is active even when OpenEars is suspended . To avoid unnecessary questions I cannot stop OpenEars as it ends up with mixing audioSession with my other sources.

The "red bar" will never disappear, even when the microphone is not in use by your application unless you explicitly stop the audio session. This is a security measure Apple has put in place to alert users of your application that it is listening to their microphone, even if you aren't doing anything with the microphone data at that exact moment.

If you are using AUAudioUnit , you may have some luck setting isInputEnabled to false .

I'm not sure if it falls into stopping OpenEars case per se, but have you tried switching AudioSessionCategory when your app goes into background/suspended mode? If you switch to a category that doesn't allow microphone input, my guess is it would stop the microphone. Then you could reset to the correct category when your app resumes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM