1

我想使用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];
    }
}
4

1 回答 1

1

关闭屏幕捕获时,您似乎没有设置任何视频捕获器。这一行:

        _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;    
    }
}
于 2016-07-21T21:26:07.153 回答