1

I am playing around AudioSessions in iOS and I want to use the built in mic of the iphone as audio input route even if an external headset (including mic) is plugged in. I'm able to detect if a headset is plugged in using the following code:

CFStringRef route;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &propertySize, &route);

if((route == NULL) || (CFStringGetLength(route) == 0)){
    // Silent Mode
    NSLog(@"AudioRoute: SILENT");
} else {
    NSString* routeStr = (NSString*)route;
    NSLog(@"AudioRoute: %@", routeStr);


    NSRange headsetRange = [routeStr rangeOfString : @"Headset"];

    if(headsetRange.location != NSNotFound) {
        NSLog(@"Headset")
        //route Audio IN to built-in mic.
    }

    .... more code

So, any ideas how to do this?

Daniel S.
  • 6,458
  • 4
  • 35
  • 78
Diffy
  • 735
  • 1
  • 15
  • 34
  • I was under the impression that the phone detects the presence of a mike, and only disables the phone mike if a mike is actually plugged in. It looks for a certain resistance between the "shell" and the ring closest to the cable, and if it's not between certain upper and lower bounds the mike is not detected. But if you have a headset with mike you're gonna have problems. – Hot Licks Apr 11 '12 at 11:19
  • 1
    (A simple "fix" might be to use a short stereo extension cord.) – Hot Licks Apr 11 '12 at 11:21
  • what audio input do you want to route to the built in mic? Do you mean you want to use an external headset as input? – Max MacLeod Nov 12 '12 at 17:07
  • Recording through internal mic and simultaneous playback through a headset's earphones (and headset's mic is not unused) was impossible in iOS6. In iOS7, this is possible through the API extensions found in the AVAudioSession class. – Daniel S. Jul 19 '14 at 10:46

0 Answers0