gpt4 book ai didi

ios - AVAudioSession 未检测到已连接的蓝牙设备

转载 作者:可可西里 更新时间:2023-11-01 02:02:20 28 4
gpt4 key购买 nike

我正在使用以下代码来检测可用的输出,但它没有接收到我连接的蓝牙设备。我知道我的蓝牙设备已正确连接,因为我正在用它播放音乐。

let session = AVAudioSession.sharedInstance()
for description in session.currentRoute.outputs {
if description.portType == AVAudioSessionPortHeadphones {
NSLog("headphone plugged in")
let alertActin = UIAlertAction(title: "Headphones", style: UIAlertActionStyle.default, handler:nil)
alertActin.setValue(UIColor.blue, forKey: "titleTextColor")
alert.addAction(alertActin)
} else if description.portType == AVAudioSessionPortBluetoothA2DP {
NSLog("Bluetooth plugged in")

let alertActin = UIAlertAction(title: description.portName, style: UIAlertActionStyle.default, handler:nil)
alertActin.setValue(UIColor.blue, forKey: "titleTextColor")
alert.addAction(alertActin)
} else if description.portType == AVAudioSessionPortBluetoothLE {
NSLog("Bluetooth plugged in")

let alertActin = UIAlertAction(title: description.portName, style: UIAlertActionStyle.default, handler:nil)
alertActin.setValue(UIColor.blue, forKey: "titleTextColor")
alert.addAction(alertActin)
}
else {
NSLog("")
}
}

最佳答案

也许您需要按照建议指示 AVAudioSession 首先允许蓝牙输出 here .

请注意 this post不鼓励使用 AVAudioSessionCategoryPlayAndRecord 并建议在使用输出设备时使用 AVAudioSessionCategoryPlayback。

关于ios - AVAudioSession 未检测到已连接的蓝牙设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45467439/

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