Reputation: 6437
I'm having issues with Bluetooth playback but only on certain bluetooth devices. Other apps work fine on these same bluetooth devices. Am I missing something with the way I'm setting the category for my AVAudioSession
?
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayAndRecord, with: [.defaultToSpeaker, .allowBluetooth, .allowAirPlay])
try session.setActive(true)
session.requestRecordPermission({(granted:Bool) in
if granted {
Variables.appHasMicAccess = true
} else {
Variables.appHasMicAccess = false
}
})
} catch let error as NSError {
print("AVAudioSession configuration error: \(error.localizedDescription)")
}
Solution was to add an additional option .allowBluetoothA2DP
. This was introduced in iOS 10.
Starting with iOS 10.0, apps using the playAndRecord category may also allow routing output to paired Bluetooth A2DP devices. To enable this behavior, you need to pass this category option when setting your audio session's category.
More details here
Upvotes: 2
Views: 3517
Reputation: 758
If the playback is on a speaker which uses A2DP, considering setting the session like this:
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord,
mode: AVAudioSessionModeVideoRecording,
options: [.defaultToSpeaker, .allowAirPlay, .allowBluetoothA2DP])
try audioSession.setActive(true)
} catch let error {
print("audioSession properties weren't set!", error)
}
Notice the option ".allowBluetoothA2DP"
Hope that helps
Upvotes: 6