我正在寻找一种显示可用音频输出的列表的方法,如callkit一样-它显示列出了设备的ActionSheet-查看照片(在连接蓝牙扬声器和耳机时触摸音频按钮的正常通话)。
是否有可能使用一段代码显示此操作表?现在,我对枚举和显示音频输出的搜索使我能够枚举输入并以某种方式或用户multiRoute类别将其映射(请参见List available output audio target AVAudioSession)。也许还有其他一些本机/简便方法?
答案 0 :(得分:0)
我尝试这样做,但是没有运气。 我想到的最接近的解决方案是使用以下方法检测是否连接了耳机:
extension AVAudioSession {
static var connectedHeadphones: AVAudioSessionPortDescription? {
return sharedInstance().currentRoute.outputs.first(where: { $0.isHeadphones })
}
}
extension AVAudioSessionPortDescription {
var isHeadphones: Bool {
return portType == AVAudioSession.Port.headphones || portType == AVAudioSession.Port.bluetoothA2DP
}
}
,然后将其设置为AVAudioSession:
try session.setPreferredInput(connectedHeadphones)
答案 1 :(得分:0)
好的,过了一段时间我可以回答我的问题-很遗憾,这是不可能的。唯一的选择是处理AVAudioSession.availableInputs以获得输入列表,并使用它来构建和UIAlertController,并使用setPreferredInput和overlayOutputAudioPort的组合来设置用户的选择。