Ios A音频会话在某些蓝牙设备上不工作
我在蓝牙播放方面有问题,但仅限于某些蓝牙设备。其他应用程序在这些相同的蓝牙设备上运行良好。我为我的Ios A音频会话在某些蓝牙设备上不工作,ios,swift,bluetooth,avaudiosession,Ios,Swift,Bluetooth,Avaudiosession,我在蓝牙播放方面有问题,但仅限于某些蓝牙设备。其他应用程序在这些相同的蓝牙设备上运行良好。我为我的视频会话设置类别的方式是否遗漏了什么 let session = AVAudioSession.sharedInstance() do { try session.setCategory(AVAudioSessionCategoryPlayAndRecord, with: [.defaultToSpeaker, .allowBluetooth, .allowAirPl
视频会话设置类别的方式是否遗漏了什么
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中引入的
从iOS 10.0开始,使用Play和Record类别的应用程序也可以允许路由输出到配对的蓝牙A2DP设备。要启用此行为,您需要在设置音频会话的类别时传递此类别选项
更多详细信息如果播放在使用A2DP的扬声器上,请考虑如下设置会话:
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”
希望这有帮助你到底面临什么问题?设备是耳机还是扬声器?它支持A2DP还是仅支持HFP(如果它的耳机)@Sunil设备是扬声器而不是耳机。它确实支持A2DP。问题是一些蓝牙设备(随机的,还没有确定模式)无法从我的应用程序播放音频。在我的情况下,我丢失了.allowBluetoothA2DP
和设置活动(true)
,并且只有在我运行代码时耳机已经连接时才会显示。非常混乱。无论如何,这有帮助。