Recording sound while playing music in Swift (iOS)

Viewed 597

I would like to create an iOS app in Swift that monitors the sound level while simultaneously playing music from any other app through a headset (wired and Bluetooth). The monitoring currently works only while music is automatically playing through the earpiece, not the earphones or built-in speakers. Is it possible to implement the .allowBluetooth and .mixWithOthers options simultaneously, or solve this issue in any other way? Thanks a lot! :-)

 let audioSession = AVAudioSession.sharedInstance()
    do {
        try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSessionCategoryOptions.mixWithOthers)

        try audioSession.setActive(true)
        try recorder = AVAudioRecorder(url:url, settings: recordSettings)

    } catch {
        return
   }
0 Answers
Related