0

Our app uses playAndRecord category with options of interruptSpokenAudioAndMixWithOthers, allowBluetoothA2DP, allowAirPlay & defaultToSpeaker, and while backgrounded, Spotify or other music apps play normally when the iPhone is not connected to anything or is connected to Bluetooth. However, once iPhone is connected to CarPlay either via Bluetooth or via USB cable, the music apps' playback quality become flat which suggests the recording is using the Hands Free Profile (which would also happen if allowBluetooth is set and connected to Bluetooth devices) - is there any way to keep using the iPhone microphone to record while connected to CarPlay so that we can allow music apps to play normally?

hyouuu
  • 2,471
  • 2
  • 27
  • 37

1 Answers1

1

First, playAndRecord and allowBluetoothA2DP are contradictory. A2DP cannot record. Also, I'm unclear why you would include both defaultToSpeaker and any of the allow... options. Do you want to play to the speaker or not?

The poor audio quality is precisely due to HFP. I believe this is mostly a duplicate of iOS App Bluetooth Audio Coming out in "Phone Mode.", and the answers there apply. Either use A2DP and the phone's microphone (rather than the car's), or use HFP and have poor audio quality. CarPlay doesn't particularly factor into this.

If you control the car audio system, then you can create your own independent audio channel to the phone. This is what I've generally done when working on earbuds. We created a custom audio encoding, and streamed it over iAP2. But you have to control the firmware of the device to do this. The standard protocols don't allow it.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • Thanks Rob! But the problem is that we only use `allowBluetoothA2DP` without `allowBluetooth`, which supposedly would not use HFP, but after connecting to CarPlay it's still doing HFP audio quality - any idea why it would happen? – hyouuu May 11 '23 at 15:48
  • 1
    I assume you're still using `playAndRecord`? Are you using the phone's built-in microphone rather than the car's? (You should be able to request that with `setPreferredInput` on the audio session.) That's what I mean by "use A2DP and the phone's microphone (rather than the car's)." `allowBluetoothA2DP` is incompatible with `playAndRecord` if you're trying to use the car's microphone. (A2DP cannot record.) – Rob Napier May 11 '23 at 16:26
  • Yes we need to use `playAndRecord` as that's our app's core functionality. But I didn't know about `setPreferredInput` - thanks for pointing that out! Will try and see if that just solves the problem. Would this make it use iPhone's microphone? `if let iPhoneInput = AVAudioSession.sharedInstance().availableInputs?[0] { try? audioSession.setPreferredInput(iPhoneInput) }` – hyouuu May 12 '23 at 16:51
  • 1
    You'll want to check for the input that has the port `builtInMic`. – Rob Napier May 12 '23 at 17:07
  • Wanted to report back what we found using `buildInMic` with CarPlay - it got really weird behavior, as the iOS volume bar started to jump up and down continuously, seemingly fighting itself, and we wonder if it's an iOS bug with `builtInMic` and CarPlay. Have you experienced similar issues ever? We connected to a Porsche CarPlay as you mentioned manufacture plays a big part to it. – hyouuu May 17 '23 at 08:51
  • I'm not familiar with that symptom. – Rob Napier May 17 '23 at 13:19