The iPhone 5 has 3 mics. Can I change from which one I'm recording?

拟墨画扇 提交于 2019-12-04 10:32:51
// set up the audio session
NSError *error = nil;

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
[audioSession setActive:YES error:&error];

if (error != nil) { NSLog(error); }


// all available inputs
NSArray* inputs = [audioSession availableInputs];

// Locate the port corresponding to the built-in microphone
for (AVAudioSessionPortDescription* port in inputs)
{
    if ([port.portType isEqualToString:AVAudioSessionPortBuiltInMic])
    {
        [self setBuiltInMicPort:port];
        break;
    }
}

// list all microphones
for (AVAudioSessionDataSourceDescription *micType in [audioSession inputDataSources]) {
    NSLog(@"%@ -- %@ -- %@ -- %@", micType.dataSourceID, micType.dataSourceName, micType.location, micType.orientation );

    if ([micType.orientation isEqualToString:@"Front"]) // or @"Back" or @"Bottom"
    {
        [micType setPreferredPolarPattern:AVAudioSessionPolarPatternOmnidirectional error:&error]; // optional
        [self.builtInMicPort setPreferredDataSource:micType error:&error];   
    }
}

This is basic example how to select different built-in microphones in the iPhone. Please keep in mind that the number of microphones differs: iPhone 5 and later has three microphones while previous generations have only two microphones (no back mic).

For more information read Apples Technical Q&A.

I've just verified that Skype switches to the top microphone when using the front camera. Now I only need to verify that I can switch quickly between the top and bottom microphone by starting video capturing from the front camera and then stopping it again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!