ios - Sinch 视频通话声音来自前置扬声器

标签 ios swift sinch

我已经在 ios swift 项目中实现了 sinch 视频通话我已经遵循了 sinch 实现文档中给出的所有过程 https://www.sinch.com/docs/video/ios/#calling .而且我能够成功地实现,但我在来自前置扬声器的视频声音方面遇到了问题。我怎么解决这个问题??在我的代码下面:

var client: SINClient?
var sinCall : SINCall?

配置信奇

//MARK: Configuring Sinch Delegate
func configuringSinch(){
    //Configuring Client Key
    client = Sinch.client(withApplicationKey: Constants.SINCH_APP_KEY, applicationSecret: Constants.SINCH_PRIVATE_KEY, environmentHost: Constants.SANDBOX_ENVIRONMENT, userId: Utility().getUserId())

    client?.call().delegate = self
    client?.setSupportCalling(true)
    client?.enableManagedPushNotifications()
    client?.start()
    client?.startListeningOnActiveConnection()

    let vcCont = client?.videoController()
    self.vwLocalView.addSubview((vcCont?.localView())!)

    self.sinCall?.delegate = self

}

//MARK: Sinch Video Call Delegate
func clientDidStart(_ client: SINClient!) {
    print("Client Did Start")
}

func clientDidFail(_ client: SINClient!, error: Error!) {
    print("Client failed : \(error)")
    player?.stop()
}
func clientDidStop(_ client: SINClient!) {
    print("Client Did Stop")
    player?.stop()
}

    //MARK: Video Call Did Recieve
func client(_ client: SINCallClient!, didReceiveIncomingCall call: SINCall!) {
    print("Did Recieve Incoming Call")

    playRingtoneSound() // Playing Audio
    call.delegate = self;
    self.sinCall = call
}

 //MARK: Call Did Add Video Track
func callDidAddVideoTrack(_ call: SINCall!) {
    let videoCont = client?.videoController()
    vwRemoteView.addSubview((videoCont?.remoteView())!)
}

func callDidEnd(_ call: SINCall!) {
    sinCall?.hangup()

}

最佳答案

这就是您如何管理 SINAudioController 来管理音频输出。

func audioController() -> SINAudioController {
        return (client?.audioController())!
    }

//MARK: Video Call Did Recieve
func client(_ client: SINCallClient!, didReceiveIncomingCall call: SINCall!) {
    audioController().enableSpeaker()

    playRingtoneSound() // Playing Audio
    call.delegate = self;
    self.sinCall = call
}

// In SINCallDelegate
func callDidEstablish(_ call: SINCall!) {

    //to disableSpeaker
    audioController().disableSpeaker()
}

试试这个手动管理音频输出 session

// MARK: AudioOutput Session

// to enable front speaker manually
func setSessionPlayerOn()
{
    do {
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)
    } catch _ {
    }
    do {
        try AVAudioSession.sharedInstance().setActive(true)
    } catch _ {
    }
    do {
        try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.none)
    } catch _ {
    }
}

// to enable speaker manually
func setSessionPlayerSpeaker()
{
    do {
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord)
    } catch _ {
    }
    do {
        try AVAudioSession.sharedInstance().setActive(true)
    } catch _ {
    }
    do {
        try AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.speaker)
    } catch _ {
    }
}

// to turnoff AudioOutput Session manually
func setSessionPlayerOff()
{
    do {
        try AVAudioSession.sharedInstance().setActive(false)
    } catch _ {
    }
}

关于ios - Sinch 视频通话声音来自前置扬声器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47978013/

相关文章:

ios - 需要有关 Objective-C 中二进制搜索树实现的指导

ios - iphone:尝试将图像导出为电影时,电影已损坏

ios - 是否可以单击一个 imageView 并打开一个新的 View Controller?

java - Android 9 上相机 "1"的 Sinch VideoCaptureThread 问题

ios - 自动布局 : Xcode 6: Centering UI elements

ios - AudioUnitRender Error -50 含义

ios - 无效的文件输出 AVAssetExport

ios - Swift Segmented Control Change Index Event,TableView 不更新

ios - 信奇短信验证SINVerificationErrorDomain Code=3

android - 在 Android 上测试电话 session