App不会将音频最初路由到耳机

问题描述 投票:0回答:1

我有一个使用Sinch SDK和CallKit实现的VOIP应用。除了插入设备的耳机时之外,其他一切都正常。在后一种情况下,当通话开始时,音频仍会通过设备的主扬声器传送。如果我在通话期间拔下并重新插入了耳机,则音频将正确地路由到耳机。

我正在做的是

func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
    guard let c = self.currentCall else {
        action.fail()
        return
    }

    c.answer()

    self.communicationClient.audioController().configureAudioSessionForCallKitCall()
    action.fulfill()
}

操作系统是否应自动解决此问题?

ios swift sinch callkit
1个回答
0
投票

似乎Sinch SDK会覆盖输出音频端口。在配置音频会话后,尝试运行此代码:

do {
    try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
} catch {
    print("OverrideOutputAudioPort failed: \(error)")
}

如果不起作用,请尝试自行配置音频会话,如果可以,请不要依赖Sinch SDK。用以下内容替换configureAudioSessionForCallKitCall调用:

let session = AVAudioSession.sharedInstance()
do {
    try session.setCategory(
        .playAndRecord,
        mode: .voiceChat,
        options: [.allowBluetooth, .allowBluetoothA2DP])
    try session.setActive(true)
} catch {
    print("Unable to activate audio session: \(error)")
}
© www.soinside.com 2019 - 2024. All rights reserved.