When I set the AVAudioSessionCategory avAudioSessionCategory: AVAudioSessionCategory.playAndRecord, sound to come out of the built-in speaker instead of Bluetooth headphones。ios17 。It is normal in IOS 16 or 15
final session = await AudioSession.instance; await session.configure(AudioSessionConfiguration( avAudioSessionCategory: AVAudioSessionCategory.playAndRecord, avAudioSessionCategoryOptions:AVAudioSessionCategoryOptions.allowBluetooth | AVAudioSessionCategoryOptions.allowBluetoothA2dp, avAudioSessionMode: AVAudioSessionMode.defaultMode, avAudioSessionRouteSharingPolicy: AVAudioSessionRouteSharingPolicy.defaultPolicy, avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none, androidAudioAttributes: const AndroidAudioAttributes( contentType: AndroidAudioContentType.music, flags: AndroidAudioFlags.none, usage: AndroidAudioUsage.media, ), androidAudioFocusGainType: AndroidAudioFocusGainType.gain, androidWillPauseWhenDucked: true, ));
How to make sound output from Bluetooth instead of speakers in IOS 17?
How to make sound output from Bluetooth instead of speakers in IOS 17?
Post
Replies
Boosts
Views
Activity
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSession.Category.playback)
try session.setActive(true)
//playAndRecord <AVAudioSessionPortDescription: 0x2828dc2b0, type = Speaker; name = 扬声器; UID = Speaker; selectedDataSource = (null)>
//playback <AVAudioSessionPortDescription: 0x28204c1a0, type = BluetoothA2DPOutput; name = M2; UID = 00:02:5C:22:22:11-tacl; selectedDataSource = (null)>
print(session.currentRoute.outputs)
} catch {
print(error)
}
when I ssession.setCategory(AVAudioSession.Category.playback) audio play output a2dp ble devices.
session.currentRoute.outputs print bellow
`<AVAudioSessionPortDescription: 0x28204c1a0, type = BluetoothA2DPOutput; name = M2; UID = 00:02:5C:22:22:11-tacl; selectedDataSource = (null)>
when I ssession.setCategory(AVAudioSession.Category.playAndRecord)
output
<AVAudioSessionPortDescription: 0x2828dc2b0, type = Speaker; name = 扬声器; UID = Speaker; selectedDataSource = (null)>
BluetoothA2DPOutput is gone.
but it is normal in ios15-16.
Is there any solution? I want to record audio and play music at the same time. And the music is output from the Bluetooth speaker