ios - 音频输出 callkit ActionSheet - 可以从代码开始吗?

标签 ios swift avaudiosession

我正在寻找一种像 callkit 那样显示可用音频输出列表的方法 - 它显示包含列出的设备的 ActionSheet - 请参阅照片(连接蓝牙扬声器和耳机时触摸音频按钮的正常通话)。

normal call with audio button touched while bluetooth speaker and headphones connected

是否有可能使用一段代码来显示此操作表?现在,我关于枚举和显示音频输出的搜索让我枚举输入并以某种方式或用户多路由类别映射它(请参阅 List available output audio target AVAudioSession )。也许有一些更原生/简单的方法?

最佳答案

我尝试这样做,但没有成功。 我认为最接近的解决方案是使用以下方法检测耳机是否已连接:

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:

尝试 session.setPreferredInput(connectedHeadphones)

关于ios - 音频输出 callkit ActionSheet - 可以从代码开始吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54130169/

相关文章:

ios - 从 UITabBarController 在当前上下文中呈现模态视图 Controller 后出现黑屏

string - 从字符串中删除最后一个字符。 swift 语言

ios - 如何初始化此Swift枚举-甚至应该使用它?

ios - AVAudioSession AVAudioSessionCategoryPlayAndRecord 故障

ios - 如何显示音频路由操作表?

使用 PhoneGap Build 时出现 iOS SDK 11 错误

ios - 如何使用 Moya 在 Swift 中上传图片?

ios - 带有特殊字符的 URL 字符串问题

ios - 将音频重新路由到蓝牙扬声器

ios - 在 iOS 中,如何在两个单元格中的文本字段之间切换?