I'm developing music application that simply play song from app. now i'm connecting bluetooth speaker to play. so i'm setting AVAudioSession
category, but it will always return error.
Code :
func setupSessionForPlaying() {
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayback, with: [.allowBluetooth])
try audioSession.setActive(true)
} catch {
fatalError("Error Setting Up Audio Session")
}
}
I'm calling this function in didFinishLaunchingWithOptions
in AppDelegate
.
But if i change setCategory
to audioSession.setCategory(AVAudioSessionCategoryPlayback)
its working fine.
Does anyone know what's wrong with this code?
Thanks
According to docs https://developer.apple.com/documentation/avfoundation/avaudiosession/categoryoptions/1616518-allowbluetooth
You can set this option only if the audio session category is playAndRecord or record.
with allowBluetooth you can not use AVAudioSessionCategoryPlayback
Hope it is helpful
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With