How to use only Airpod's microphone without stopping any music that is being played by other app?

245 Views Asked by At

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

1

There are 1 best solutions below

0
On

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
}