2016-06-11 119 views
1

我想提供屏幕共享开启/关闭 iOS的功能使用Tokbox在iOS中开启/关闭Tokbox屏幕共享目标C

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

他们有一个加速器包来做到这一点。 https://github.com/opentok/screensharing-annotation-acc-pack –

回答

1

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

 _publisher.videoCapture = nil; 

是不必要的破坏性。尽量保持一个内部参考的摄像头和屏幕capturers,并进行初始化的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;  
    } 
}