我想使用 Tokbox 在 iOS 中提供屏幕共享开/关功能。
我可以切换到设备屏幕共享,但在共享屏幕后,我无法切换回设备Camara。
我已经尝试使用以下代码。
-(void)toogleScreen{
if (isSharingEnable == YES) {
isSharingEnable = NO;
NSLog(@"%@",_publisher.description);
_publisher.videoCapture = nil;
[_publisher setVideoType:OTPublisherKitVideoTypeCamera];
_publisher.audioFallbackEnabled = YES;
} else {
isSharingEnable = YES;
[_publisher setVideoType:OTPublisherKitVideoTypeScreen];
_publisher.audioFallbackEnabled = NO;
TBScreenCapture* videoCapture =
[[TBScreenCapture alloc] initWithView:self.view];
[_publisher setVideoCapture:videoCapture];
}
}
关闭屏幕捕获时,您似乎没有设置任何视频捕获器。这一行:
_publisher.videoCapture = nil;
是不必要的破坏性。尝试保留对相机和屏幕捕获器的内部引用,并在切换屏幕功能之外初始化它们:
@implementation MyPublisher {
id <OTVideoCapture> _cameraCapture;
id <OTVideoCapture> _screenCapture;
}
然后,将切换方法更改为如下所示:
-(void)toogleScreen{
if (isSharingEnable == YES) {
isSharingEnable = NO;
[_publisher setVideoCapture:_cameraCapture];
[_publisher setVideoType:OTPublisherKitVideoTypeCamera];
_publisher.audioFallbackEnabled = YES;
} else {
isSharingEnable = YES;
[_publisher setVideoCapture:_screenCapture];
[_publisher setVideoType:OTPublisherKitVideoTypeScreen];
_publisher.audioFallbackEnabled = NO;
}
}