2016-06-11 122 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;  
    } 
}