gpt4 book ai didi

ios - AVAudioSession 在某些蓝牙设备上不工作

转载 作者:搜寻专家 更新时间:2023-11-01 07:01:50 24 4
gpt4 key购买 nike

我在蓝牙播放方面遇到问题,但仅限于某些蓝牙设备。其他应用程序在这些相同的蓝牙设备上运行良好。我为 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)")
}

更新

解决方案是添加一个附加选项 .allowBluetoothA2DP。这是在 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.

更多详情 here

最佳答案

如果在使用 A2DP 的扬声器上播放,请考虑这样设置 session :

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)
}

注意选项“.allowBluetoothA2DP”

希望对你有帮助

关于ios - AVAudioSession 在某些蓝牙设备上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50789276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com