Ios Sinch视频通话声音来自前扬声器

Ios Sinch视频通话声音来自前扬声器,ios,swift,sinch,Ios,Swift,Sinch,我已经在ios swift项目中实施了sinch视频通话,我遵循了sinch实施文件中给出的所有流程。我成功地实现了,但我的视频声音来自前置扬声器。我怎样才能解决这个问题??下面是我的代码: var client: SINClient? var sinCall : SINCall? 配置sinch //MARK: Configuring Sinch Delegate func configuringSinch(){ //Configuring Client Key client

我已经在ios swift项目中实施了sinch视频通话,我遵循了sinch实施文件中给出的所有流程。我成功地实现了,但我的视频声音来自前置扬声器。我怎样才能解决这个问题??下面是我的代码:

var client: SINClient?
var sinCall : SINCall?
配置sinch

//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()
}
尝试手动管理音频输出会话

// 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 _ {
    }
}
使用此功能

 func callDidEstablish(_ call: SINCall!) {

    let audio = APPDELEGATE.client?.audioController()
    audio?.disableSpeaker()

   // self.startCallDurationTimerWithSelector()
    appDelegate.client?.audioController().stopPlayingSoundFile()

}

这是我的工作。

这与我在视频通话时接收的传入声音无关。好的,但当您在“来自前扬声器的视频声音”中写入时,它将从扬声器输出。您可以在控制器audioController()中的任何位置使用它。enableSpeaker()。让我知道这是否有用我已将答案编辑为audioController()。enableSpeake不适用于您。您可以手动管理音频输出会话以实现此目的。您的问题是否仍然存在?修复了@Govind的问题
class MainVC: UIViewController,SINCallDelegate {
   // var client: SINClient?

    private let videoController = SinchManager.sharedInstance.client!.videoController()
    private let audioController = SinchManager.sharedInstance.client!.audioController()


    private let callClient: SINCallClient
    private var call: SINCall!

    let username: String

    @IBOutlet weak var otherView: UIView!

   // private var mainView: SinchView { return view as! SinchView }

    @IBAction func call_btn(_ sender: UIButton) {
        answer()
    }
    @IBAction func end_btn(_ sender: UIButton) {
        decline()
    }


    override func loadView() {
       // view = SinchView()
        view = otherView
    }

    init(username: String) {
        self.username = username
        self.callClient = SinchManager.sharedInstance.client!.call()

        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder aDecoder: NSCoder) {
        print("init(coder:) has not been implemented " + String(describing: aDecoder))

        fatalError("init(coder:) has not been implemented " + String(describing: aDecoder))
    }

    override func viewDidLoad() {
        super.viewDidLoad()


        call.delegate = self

        //self.mainView.videoView.addSubview(self.videoController.localView())
        otherView.addSubview((self.videoController?.localView())!)

        self.videoController?.localView().contentMode = .scaleToFill

        if self.call.direction == SINCallDirection.incoming {
            self.audioController?.startPlayingSoundFile(self.pathForSound(string: "incoming.wav") as String, loop: true)
        }

        if self.call.details.isVideoOffered {
            print("video offered")
            //self.mainView.videoView.addSubview(self.videoController.localView())
            otherView.addSubview((self.videoController?.localView())!)

            self.videoController?.localView().contentMode = .scaleToFill
        }

        otherView.addSubview((self.videoController?.localView())!)
       // mainView.answerButton.addTarget(self, action: #selector(answer), forControlEvents: .TouchUpInside)
       // mainView.declineButton.addTarget(self, action: #selector(decline), forControlEvents: .TouchUpInside)
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.audioController?.enableSpeaker()
    }

    func pathForSound(string: String) -> NSString {
        let nsSt = Bundle.main.resourcePath! as NSString

        return nsSt.appendingPathComponent(string) as NSString
    }

    func answer() {
        call.answer()
    }

    func decline() {
        call.hangup()
    }

    func callDidEstablish(call: SINCall!) {
        print("callDidEstablish")
        let audio = SinchManager.sharedInstance.client!.audioController()
        audio?.disableSpeaker()

        // self.startCallDurationTimerWithSelector()
       SinchManager.sharedInstance.client!.audioController().stopPlayingSoundFile()
    }

    func callDidEnd(call: SINCall!) {
        print("callDidEnd")
    }

    func callDidProgress(call: SINCall!) {
        print("callDidProgress")
        self.audioController?.startPlayingSoundFile(self.pathForSound(string: "ringback.wav") as String, loop: true)
    }

    func callDidAddVideoTrack(call: SINCall!) {
        print("callDidAddVideoTrack")
        otherView.addSubview((self.videoController?.localView())!)
    }