ios - iOS Objective C 中的 Tokbox 屏幕共享开/关切换

标签 ios objective-c opentok tokbox screensharing

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

具有不必要的破坏性。尝试保留对相机和屏幕捕获器的内部引用,并在 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;    
    }
}

关于ios - iOS Objective C 中的 Tokbox 屏幕共享开/关切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37763898/

相关文章:

ios - 完成所有行后如何停止uitableview

ios - 在 nativescript 中的模态中打开模态

objective-c - 调用 SQLite 方法时的 EXC_BAD_ACCESS

android - opentok-android-sdk-2.3.1 和 OpenSSL 漏洞问题

javascript - 使用适用于移动设备的 javascript 将摄像头流式传输到服务器

ios - 如何让 UITabBar 选择指示器图像填满整个空间?

ios - NSData荒谬的长度错误

iphone - NSString 子字符串

objective-c - 有没有办法使用 CFNetwork 从 ftp 服务器删除文件/文件夹?

ios - 应用程序从后台状态转到前台时的 OpenTok 视频通话问题