Search code examples
iosswifttwilioavaudioplayerspeaker

iOS Change device speaker


I need to implement iPhone speaker (ear and bottom) change during audio call (using TwilioVideo SDK for connection) Mine code:

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)
}

It works without any exceptions, but don't change audio output speaker


Solution

  • Twilio developer evangelist here.

    You should not use AVAudioSession APIs directly with Twilio Video. Instead, you should use the TVIAudioController and set the audioOutput property to one of the options enumerated in TVIAudioOutput.

    TVIAudioController.sharedController().audioOutput = .TVIAudioOutputVideoChatSpeaker
    

    Let me know if that helps.