0

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

Arasuvel
  • 2,971
  • 1
  • 25
  • 40
Viktor
  • 1,020
  • 1
  • 9
  • 22

1 Answers1

1

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.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • That works well, thank you. But is there any way to set category to audioSession inside of Twilio lib? – Viktor Oct 03 '17 at 10:12
  • The four available output settings are: TVIAudioOutputVideoChatDefault, TVIAudioOutputVideoChatSpeaker, TVIAudioOutputVoiceChatDefault and TVIAudioOutputVoiceChatSpeaker. – philnash Oct 03 '17 at 10:15
  • I mean AVAudioSessionCategoryPlayAndRecord category. I need to display green in-call statusBar, and according to https://stackoverflow.com/a/31704318/4899912, I need to just set this category to AVAudioSession. Setting it to sharedInstance doesn't help – Viktor Oct 03 '17 at 10:18
  • Oh, the video SDK sets the category to `AVAudioSessionCategoryPlayAndRecord` automatically, it says that here: https://media.twiliocdn.com/sdk/ios/video/releases/1.3.2/docs/Constants/TVIAudioOutput.html. That answer suggests some other settings you need to add too, like `UIBackgroundMode` set to `voip` in your info.plist. – philnash Oct 03 '17 at 10:29
  • My fault - set only 'voip', when need both 'audio' and 'voip' keys. But it's displayed as red (recording) status. Any chances to change it to green (in-call) ? – Viktor Oct 03 '17 at 10:42
  • I don't know I'm afraid. [This answer seemed to claim you could get red or green](https://stackoverflow.com/questions/7246306/sbstatusbarcontroller-instance/7283146#7283146), hope it helps. – philnash Oct 03 '17 at 10:59
  • audioOutput is not found in 2.0.0 Version. Is it possible to call `TVIAudioController` ? – Balasubramanian May 02 '18 at 09:31
  • There are docs on specifying audio output in version 2 here: https://www.twilio.com/docs/video/ios-v2-configuring-audio-video-inputs-and-outputs#selecting-specific-audio-routes – philnash May 03 '18 at 03:53