twilio / video-quickstart-ios

Twilio Video Quickstart for iOS
https://www.twilio.com/docs/api/video
MIT License
457 stars 177 forks source link

switching off a speaker on a voice call using TwilioVideo #634

Open Irynavb opened 2 years ago

Irynavb commented 2 years ago

Hello,

I'm having an issue switching off a speaker on a voice call using TwilioVideo (for an iOS application). As the audio routes default to the speaker, I am overriding it while configuring an audio session using the reference from the issues https://github.com/twilio/video-quickstart-ios/issues/307 and https://github.com/twilio/video-quickstart-ios/issues/379. However, using the following code does not seem to achieve the preferred result.

let audioDevice = DefaultAudioDevice()
    TwilioVideoSDK.audioDevice = audioDevice

    audioDevice.block = {
      DefaultAudioDevice.DefaultAVAudioSessionConfigurationBlock()

      do {

        let session = AVAudioSession.sharedInstance()
        print("set audio session")
        try session.setCategory(.playAndRecord, mode: .voiceChat)
        try session.overrideOutputAudioPort(.none)

     // tried adding the lines with an if-statement below as well as overriding the input above to `.none`
        if isSpeaker {
          try AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
        }
        try session.setActive(true, options: .notifyOthersOnDeactivation)
      } catch let error {
        print("Error while configuring audio session: \(error)")
      }

    }
    audioDevice.block()
  }

Thank you in advance for your help!

SrmNarola commented 1 year ago

Hi @Irynavb Would you please share DefaultAudioDevice() class code?