0

我在我的应用程序中使用 OpenTok SDK 进行视频通话。我需要在单击按钮时实现相机切换功能。但它不起作用。

我在用

@IBAction func cameraButtonAction(_ sender: Any) { publisher?.cameraPosition = AVCaptureDevice.Position.back } 点击按钮

连接会话时创建发布者

  func sessionDidConnect(_ session: OTSession) {
    print("The client connected to the OpenTok session.")
    let settings = OTPublisherSettings()
    settings.name = UIDevice.current.name 
    guard let publisher = OTPublisher(delegate: self, settings: settings) else {
        return
    }

    var error: OTError?
    session.publish(publisher, error: &error)
    guard error == nil else {
        print(error!)
        return
    }

    guard let publisherView = publisher.view else {
        return
    }
    let screenBounds = UIScreen.main.bounds
    publisherView.frame = CGRect(x: screenBounds.width - 150 - 20, y: screenBounds.height - 150 - 20, width: 150, height: 150)
    view.addSubview(publisherView)
}
4

1 回答 1

1

似乎您没有设置发布者。这是一个简单的错误,可能发生在任何人身上。

guard let publisher = OTPublisher(delegate: self, settings: settings) else {
    return
}

self.publisher = publisher

将此行添加到您正在初始化发布者的代码中。

于 2020-04-01T07:21:07.843 回答