[IOS] iphone detection headphone Insert/unplug

Source: Internet
Author: User

Recording and playback in the development process there are a number of problems, the main problem is three: detect whether there is a sound input device when there are multiple sound output devices, the specified sound output device detects the insertion and pull-out of headphones

First, for devices such as itouch and the ipad that do not have a microphone, you need to check to see if the headset is plugged in and it's relatively easy for the iphone because it's close to bringing a microphone. The second problem is that when an output device such as an ear machine is plugged into an outgoing device, a plurality of output devices appear, requiring the implementation to specify where the sound is to be exported in the program. Third, inserting/unplugging headphones necessarily causes a change in the sound output device, and if a headset with a microphone is inserted/unplugged on itouch and the ipad, it will inevitably cause changes in the sound input device.

1. Detect sound Input devices

[plain] view plain copy print?   -(BOOL) Hasmicphone {return [[avaudiosession sharedinstance] inputisavailable]; } 2. Detecting Sound output devices
For the output device detection, we only consider 2 cases, one is the device itself out (Itouch/ipad/iphone), one is currently inserted with out headphones. iOS has already provided a way to get all of the current sound devices, and we just need to check to see if we have the ones we care about in these devices.
Get all current sound devices:
[plain] view plain copy print?   Cfstringref Route;   UInt32 propertysize = sizeof (CFSTRINGREF);   Audiosessiongetproperty (Kaudiosessionproperty_audioroute, &propertysize, &route); All possible sound devices on iOS include:

[CPP]   View plain copy print/* known values of route:  *  " Headset "  * " headphone "  * " Speaker "  * " Speakerandmicrophone "  * " Headphonesandmicrophone "  * " headsetinout "  * " Receiverandmicrophone " 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.