I am developing an iOS application (targetted specifically for iPhone, at the moment) that requires the application to record audio only from iPhone internal microphone (even when headphone/headset is plugged in), and playback at headphone (let's assumed headphone is plugged in for now).
I am wondering if this is currently possible with the available APIs? If so, can anyone please shed some light on how do I go about doing this?
Thanks!
I believe the answer to this question to be 'no'. I used an iPhone 4 and the new-to-iOS 4 AVFoundation to experiment, focussing on the AVCaptureDevice class.
I added the following to an application:
So that asks that all devices that can be used for capturing audio and/or video be listed. Without the headphones plugged in, I get:
With the headphones plugged in I get:
So the iPhone microphone drops off the list of available AVCaptureDevices as soon as the headphones become available. To probe this further, I added a quick bit of code to grab the AVCaptureDevice instance for the available audio device and to print its unique ID. For both the device identifying itself as "iPhone Microphone" and the device identifying itself as "Headphones", I got:
It would seem to me to be obvious that two devices can't have the same unique ID, so clearly it's the same device changing its state. Although AVCaptureDevices have a lot of stuff for setting state, it's limited to visual things like focus, exposure, flash and white balance.
Since apple changed the audio system again starting from 7.0 I'm going to post the update-ed code over here:
Remember to add observer since the audio session's delegate is deprecated too:
PS: you dont need to reset the category here (as in 6.0)
It is not possible, I try to figure out with route changed listener (with AudioSession). My result is : you can't configure separately input or output because of categories provided by Apple. I try *PlayAndRecord, when I pair a bluetooth device, route change like this :
In fact, my bluetooth is not an headset, just speakers... So for me there is no solution.
Looks like its really not possible.
My goal is to send output to bluetooth headsets and record input from it too. As far I can see, my best options are: "PlayAndRecord + AllowBluetoothInput" property (iphone 4, nokia BH-214 headset)
IMPORTANT thing is that according to the apple documentation, you always have to RE-override your audio category when audio route changes!
THIS IS MY ROUTE CHANGE LISTENER method, that prints: RouteChangeReasons, outputRoute, audioRout:
}
I am pretty confident this is possible via your application's Audio Session:
Dig on these docs:
And let me know how it goes!