Opentok和CallKit

时间:2018-05-24 06:36:21

标签: ios swift opentok callkit

我正在尝试使用OpentokCallKit进行音频和视频通话,我已经按照OpenTok https://github.com/opentok/CallKit/tree/master/CallKitDemo

提供的演示进行了演示

我面临的问题是,当我向另一个人进行音频通话时,它会启动扬声器而不是内置接收器。我尝试了他们的演示,它也有同样的问题。

然后我尝试了由Apple提供的https://developer.apple.com/library/content/samplecode/Speakerbox/Introduction/Intro.html#//apple_ref/doc/uid/TP40017290,但在实施AudioController后,新的呼叫以内置扬声器开始,并自动切换到扬声器,无法制作输出变化。

2 个答案:

答案 0 :(得分:0)

你是如何发布你的流的?

 let settings = OTPublisherSettings()
 settings.name = "\(userID)"
 guard let publisher = OTPublisher(delegate: self, settings: settings) 
  else {
        return
    }
    yourStream = publisher
    yourStream?.publishAudio = false
    yourStream?.publishVideo = true
    var error: OTError?
    session?.publish(publisher, error: &error)
    guard error == nil else {
        print(error!)
        return
    }

    guard let publisherView = publisher.view else {
        return
    }
   participantVideoView.addSubview(publisherView)

答案 1 :(得分:0)

我需要设置自定义音频驱动程序并设置AVAudioSession

         var audioOptions: UInt {
            if isSpeaker {
                return AVAudioSessionCategoryOptions.defaultToSpeaker.rawValue |
                    AVAudioSessionCategoryOptions.mixWithOthers.rawValue |
                    AVAudioSessionCategoryOptions.allowBluetooth.rawValue |
                    AVAudioSessionCategoryOptions.allowAirPlay.rawValue

            } else {
                return AVAudioSessionCategoryOptions.mixWithOthers.rawValue |
                    AVAudioSessionCategoryOptions.allowBluetooth.rawValue |
                    AVAudioSessionCategoryOptions.allowAirPlay.rawValue |
                    AVAudioSessionCategoryOptions.duckOthers.rawValue
            }
        }
        if isSpeaker {
            try session.setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeVoiceChat, options: AVAudioSessionCategoryOptions(rawValue: audioOptions))
        } else {
            try session.setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionModeVoiceChat, options: AVAudioSessionCategoryOptions(rawValue: audioOptions))
        }