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 "