0

I would like to use the built-in mic on the device for input and the bluetooth headset for output. My session category is and must be AVAudioSessionCategoryPlayAndRecord. I have tried using setPreferredInput: to the built-in mic but it also switches the output to the device's speakers.

I've seen this (specifically the comments) where they mention it's possible.

Community
  • 1
  • 1
Alex
  • 361
  • 1
  • 4
  • 15

1 Answers1

0

You can use this code

// create and set up the audio session

AVAudioSession* audioSession = [AVAudioSession sharedInstance];

[audioSession setDelegate:self];

[audioSession setCategory: AVAudioSessionCategoryPlayAndRecord error: nil];

[audioSession setActive: YES error: nil];


// set up for bluetooth microphone input

UInt32 allowBluetoothInput = 1;

OSStatus stat = AudioSessionSetProperty (
                         kAudioSessionProperty_OverrideCategoryEnableBluetoothInput,
                         sizeof (allowBluetoothInput),
                         &allowBluetoothInput
                        );

NSLog(@"status = %x", stat);    // problem if this is not zero

// check the audio route

UInt32 size = sizeof(CFStringRef);

CFStringRef route;

OSStatus result = AudioSessionGetProperty(kAudioSessionProperty_AudioRoute, &size, &route);
NSLog(@"route = %@", route);  

// if bluetooth headset connected, should be "HeadsetBT"

// if not connected, will be "ReceiverAndMicrophone"

// now, play a quick sound we put in the bundle (bomb.wav)

CFBundleRef mainBundle = CFBundleGetMainBundle();

CFURLRef        soundFileURLRef;

SystemSoundID   soundFileObject;

soundFileURLRef  = CFBundleCopyResourceURL (mainBundle,CFSTR ("bomb"),CFSTR ("wav"),NULL);

AudioServicesCreateSystemSoundID (soundFileURLRef,&soundFileObject);

AudioServicesPlaySystemSound (soundFileObject); 
ChrisH
  • 4,468
  • 2
  • 33
  • 42
Reshmi Majumder
  • 961
  • 4
  • 15