在iOS目标C中打开/关闭Tokbox屏幕共享打开/关闭

时间:2016-06-11 12:46:57

标签: ios objective-c opentok tokbox screensharing

我想在iOS中使用 Tokbox 提供屏幕共享开/关功能。

我可以切换到设备屏幕共享,但在共享屏幕后,我无法切换回设备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];
    }
}

1 个答案:

答案 0 :(得分:1)

看起来你在关闭screencapture时可能没有设置任何视频捕获器。这一行:

        _publisher.videoCapture = nil;

不必要的破坏性。尝试保持对相机和屏幕捕获器的内部引用,并在toggleScreen函数之外初始化它们:

@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;    
    }
}