-1

My application wants to access only Airpod's microphone (not speakers) but when I try to start recording from my app it turns of the music if it is playing. How can I only use Airpod's microphones. I dont want to stop any music that is being played by another application.

I tried to do the following. This code snippet can actually take input from Airpod's microphone but stops any other song that is being played.

try recordingSession.setCategory(.playAndRecord, mode: .measurement, options: .allowBluetooth)
try recordingSession.setActive(true)


audioRecorder = try AVAudioRecorder(url: audioFilename, settings: settings)
audioRecorder.delegate = self
audioRecorder.isMeteringEnabled = true
audioRecorder.prepareToRecord()
audioRecorder.record() 

I dont want to stop any music that is being played by another application. I just want to use Airpod's microphones

Pooja Thakoor
  • 19
  • 1
  • 2

1 Answers1

0

Try this

try recordingSession.setCategory(.playAndRecord, mode: .measurement, options: [.allowBluetoothA2DP, .mixWithOthers])

And in you AppDelegate add this code snipped to didFinishLaunchingWithOptions

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

    try! AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.ambient, mode: AVAudioSession.Mode.default, options: AVAudioSession.CategoryOptions.mixWithOthers)

    return true
}
Arie Pinto
  • 1,274
  • 1
  • 11
  • 19