iOS Change device speaker

1.5k views Asked by At

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

1

There are 1 answers

8
philnash On BEST ANSWER

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.