在 OpenTok Swift SDK 中切换相机
Toggle camera in OpenTok Swift SDK
我在我的应用程序中使用 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)
}
您似乎没有设置发布者。这是一个简单的错误,任何人都可能发生。
guard let publisher = OTPublisher(delegate: self, settings: settings) else {
return
}
self.publisher = publisher
将此行添加到您初始化发布者的代码中。
我在我的应用程序中使用 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)
}
您似乎没有设置发布者。这是一个简单的错误,任何人都可能发生。
guard let publisher = OTPublisher(delegate: self, settings: settings) else {
return
}
self.publisher = publisher
将此行添加到您初始化发布者的代码中。