InputSources actually good for?
I've tried to fetch the list of available audio input devices on an iPhone by using this code:
CFArrayRef arrayRef;
UInt32 size = sizeof(arrayRef);
OSStatus status = AudioSessionGetProperty(kAudioSessionProperty_InputSources, &size, &arrayRef);
assert(status == noErr);
NSArray *array = (__bridge NSArray *)arrayRef;
The call works and returns without error, but the results array is always empty, no matter what hardware I have connected to it. I've tried two usual headsets for mobiles, an original one from Apple and one from Samsung and two kinds of USB microphones (an iXY from Rode and an iM2X from Tascam), but the array always stays empty. So I wonder what kinds of input sources would actually be listed by this property? Is it usable at all?
By using a listener callback on the audio routes, I was able to verify that all 4 devices are detected correctly. I was also able to record audio with each of the devices, so they all work properly. I use an iPhone 4S with iOS 6.1.3 (10B329).
I'm very new to audio programming on iPhones so I don't have an answer to the question of what that particular property is good for, but if you want the list of audio inputs, I think this will work:
NSArray * ais = [[AVAudioSession sharedInstance] availableInputs];
This provides an array of AVAudioSessionPortDescription objects.
for (id object in ais) {
AVAudioSessionPortDescription * pd = (AVAudioSessionPortDescription*)object;
NSLog(@"%@",pd.portName);
}
The property you are referring to is only for audio input sources in a USB audio accessory attached through the iPad camera connection kit , as mentioned in the AudioSessionServices class reference.
To get an array that is not nil you will need to test with say a USB Audio Workstation that plugs into the iPad camera connection kit .
Here is a link that lists some hardware that uses the iPad camera connection kit .
Connecting USB audio interfaces using the Apple iPad Camera Connection Kit.
Also from the class reference
If there is no audio input source available from the attached accessory, this property's value is an empty array.
So from the list found in the above link (scroll down to List of some compatible devices sub heading), devices you would be interested in, that yield a !nil result, would be some device that offers audio input such as the Alesis iO4 , iO2 , or iO2 express .
EDIT: there's merit in the answer provided by Shawn Hershey, with regards to using a non-deprecated objective-c alternative. However you would be most interested in the portType property of the AVAudioSessionPortDescription class. (available from iOS 6.0) Two constants of interest are - AVAudioSessionPortLineIn and AVAudioSessionPortUSBAudio . The first one mentioned is for audio input through the dock connector, which is the way your test microphones mentioned connect.
In iOS 7.0 and later you can query the availableInputs property of the AVAudioSession class. In iOS 6 you can only query the currentRoute property.
I found this Technical Q&A very helpful - AVAudioSession - microphone selection
链接地址: http://www.djcxy.com/p/60180.html上一篇: Android Java:如何在传输系统音频时禁用麦克风输入?
下一篇: InputSources实际上对于?