Callkit loudspeaker bug / how WhatsApp fixed it?

前端 未结 5 1293
别那么骄傲
别那么骄傲 2021-02-02 10:08

I have an app with Callkit functionality. When I press the loudspeaker button, it will flash and animate to the OFF state (sometimes the speaker is set to LOUD but

5条回答
  •  遥遥无期
    2021-02-02 10:35

    I've fixed the issue by doing following steps.

    • In CXAnswerCallAction, use below code to set audiosession config.

      RTCDispatcher.dispatchAsync(on: RTCDispatcherQueueType.typeAudioSession) {
      let audioSession = RTCAudioSession.sharedInstance()
      audioSession.lockForConfiguration()
      let configuration = RTCAudioSessionConfiguration.webRTC()
      configuration.categoryOptions = [AVAudioSessionCategoryOptions.allowBluetoothA2DP,AVAudioSessionCategoryOptions.duckOthers,
                                       AVAudioSessionCategoryOptions.allowBluetooth]
      try? audioSession.setConfiguration(configuration)
      audioSession.unlockForConfiguration()}
      
    • After call connected, I'm resetting AudioSession category to default.

      func configureAudioSession() {
      let session = RTCAudioSession.sharedInstance()
      session.lockForConfiguration()
      do {            
          try session.setCategory(AVAudioSession.Category.playAndRecord.rawValue, with: .allowBluetooth)
          try session.setMode(AVAudioSession.Mode.default.rawValue)
          try session.setPreferredSampleRate(44100.0)
          try session.setPreferredIOBufferDuration(0.005)
      } 
      catch let error {
          debugPrint("Error changeing AVAudioSession category: \(error)")
      }
      session.unlockForConfiguration()}
      

    Thanks to SO @Алексей Смольский for the help.

提交回复
热议问题