2017-08-30 159 views
0

我需要实现iPhone音箱(耳朵和底部)的音频通话过程中的变化(使用TwilioVideo SDK连接)更改设备 矿代码:的iOS扬声器

let audioSession = AVAudioSession.sharedInstance() 

do { 
    if isSpeaker == false { 
     try audioSession.overrideOutputAudioPort(.speaker) 
     isSpeaker = true 
    } else { 
     try audioSession.overrideOutputAudioPort(.none) 
     isSpeaker = false 
    } 

    try audioSession.setActive(true) 
} catch { 
    handleError(error.localizedDescription) 
} 

这工作没有任何异常,但不要” t改变音频输出扬声器

回答

1

Twilio开发者传道这里。

您不应该直接使用AVAudioSession API与Twilio Video。相反,您应该将TVIAudioController and set the audioOutput property用于TVIAudioOutput中列举的选项之一。

TVIAudioController.sharedController().audioOutput = .TVIAudioOutputVideoChatSpeaker 

让我知道这是否有帮助。

+0

这很好,谢谢。 但是有什么方法可以将类别设置为Twilio库中的audioSession? – Viktor

+0

四种可用输出设置为:TVIAudioOutputVideoChatDefault,TVIAudioOutputVideoChatSpeaker,TVIAudioOutputVoiceChatDefault和TVIAudioOutputVoiceChatSpeaker。 – philnash

+0

我的意思是AVAudioSessionCategoryPlayAndRecord类别。我需要显示绿色的通话状态栏,根据https://stackoverflow.com/a/31704318/4899912,我需要将此类别设置为AVAudioSession。将其设置为sharedInstance并没有帮助 – Viktor