Swift中的基本Sinch示例-但没有声音

时间:2019-02-24 21:57:41

标签: swift audio sinch

首先感谢您阅读我的台词。 对于一个想法,我目前正在尝试进入Swift世界(我只有非常基本的编程知识-没有Objective C知识 )。

我尝试设置以下几行以在Sinch中创建一个非常基本的应用到应用示例。在我写完代码后,我让您知道问题出在哪里。

import UIKit
import Sinch


var appKey = "APP_KEY_FROM_MY_ACCOUNT"
var hostname = "clientapi.sinch.com"
var secret = "SECRET_FROM_MY_ACCOUNT"



class CViewController: UIViewController, SINCallClientDelegate, SINCallDelegate, SINClientDelegate  {

    var client: SINClient?
    var call: SINCall?
    var audio: SINAudioController?

    //Text field in the main storyboard
    @IBOutlet weak var userNameSepp: UITextField!



    override func viewDidLoad() {
        super.viewDidLoad()
        self.initSinchClient()
    }

    //initialize and start the client as a fixed "userA"
    func initSinchClient() {
        client = Sinch.client(withApplicationKey: appKey, applicationSecret: secret, environmentHost: hostname, userId: "userB")
        client?.call().delegate = self
        client?.delegate = self
        client?.startListeningOnActiveConnection()
        client?.setSupportCalling(true)
        client?.start()

    }
    //Did the Client start?
    func clientDidStart(_ client: SINClient!) {
        print("Hello")
    }

    //Did the Client fail?
    func clientDidFail(_ client: SINClient!, error: Error!) {
        print("Good Bye")
    }


    //Call Button in the main.storyboard ... if call==nil do the call ... else hangup and set call to nil
    //the background color changes are my "debugging" :D
    @IBAction func callSepp(_ sender: Any) {
        if call == nil{
            call = client?.call()?.callUser(withId: userNameSepp.text)
//for testing I change to callPhoneNumber("+46000000000").
// the phone call progresses (but I hear nothing),
// the phonecall gets established (but I hear nothing)
// and the phonecall gets ended (but of course I hear nothing)
            self.view.backgroundColor = UIColor.red
            call?.delegate = self
            audio = client?.audioController()
        }
        else{
            call?.hangup()
            self.view.backgroundColor = UIColor.blue
            call = nil
        }
    }

    func callDidProgress(_ call: SINCall?) {
        self.view.backgroundColor = UIColor.green
        client?.audioController().startPlayingSoundFile("/LONG_PATH/ringback.wav", loop: true)
                print("Call in Progress")
        }

//I know that this works but I don't hear anything
        func callDidEstablish(_ call: SINCall!) {
            client?.audioController().stopPlayingSoundFile()
            print("Call did Establish")
        }

    func callDidEnd(_ call: SINCall!) {
        print("Call did end")
    }



//    this works fine
    @IBAction func hangUpSepp(_ sender: Any) {
        call?.hangup()
        self.view.backgroundColor = UIColor.red
        call = nil

    }

//    i work in a "sub view controller" - so i navigate here back to the main view controller
    @IBAction func goBackMain(_ sender: Any) {
        call?.hangup()
        dismiss(animated: true, completion: nil)
        client?.stopListeningOnActiveConnection()
        client?.terminateGracefully()
        client = nil
    }

}

因此,我可以拨打我的私人电话号码,或者如果我更改为callUser,我可以拨打另一个应用程序,但听不到任何声音。我想念什么?它必须与SINAudioController和客户端的方法audioController()有关,但我不知道我在做什么错。谢谢您的帮助。

0 个答案:

没有答案