VisSDK API For Objective-C 文档

当前SDK版本1.0

创建对象

@property (strong, nonatomic) VisSDK* visClient;
@property (weak, nonatomic) IBOutlet UIView *preview;
@property (weak, nonatomic) IBOutlet UIView *playView;
...
- (void) viewDidLoad {
    ...
    _visClient = [[VisSDK alloc] init];
}

设置

//设置参数
[_visClient setApp:@"..." andStream:@"..." andPassword:@"..." andUid:...];
//关联视图
_visClient.preview.frame = _preview.bounds;
_visClient.playView.frame = _playView.bounds;
[_preview addSubview:_visClient.preview];
[_playView addSubview:_visClient.playView];

获取上麦情况

[_visClient fetchMicState:^(int state) {
    //state的第0位代表第一个麦有是否上麦,第1位代表第二个麦是否上麦
    NSLog(@"%@",[NSString stringWithFormat:@"第1个麦:%d,第2个麦:%d",state&1,(state>>1)&1]);
} onError:^(int errCode, NSString *message) {
    if (errCode == kConnectionError) {
        //连接错误
        NSLog(@"%@",message);
    } else if(errCode == kPasswordError) {
        //密码错误
        NSLog(@"%@",message);
    } else {
        //请求错误 kRequestError
        NSLog(@"%@",message);
    }
}];

开始播放合成画面

//播放合成画面
[_visClient startPlay];

停止播放合成画面

//停止播放合成画面
[_visClient stopPlay];

开启预览

//发布直播前需要先开启预览,参数表示是否使用前置摄像头
[_visClient startPreviewWithCamera:NO];

停止预览

[_visClient stopPreview];

开始发布和播放

//发布直播,并播放另一端的画面
[_visClient startPlayAndPubOnSuccess:^{
    NSLog(@"publish success");
} onError:^(int errCode, NSString *message) {
    if (errCode == kConnectionError) {
        //http连接错误
        NSLog(@"%@",message);
    } else if (errCode == kPasswordError) {
        //密码错误
        NSLog(@"%@",message);
    } else if(errCode == kPublishConflict) {
        //发布冲突
        NSLog(@"%@",message);
    } else if (errCode == kRequestError) {
        //错误的内部http请求
        NSLog(@"%@",message);
    } else {
        //发布失败 kPublishFailed
        NSLog(@"%@",message);
    }
} withFlag:0];

停止发布和播放

//停止直播和播放
[_visClient stopPlayAndPubOnSuccess:^{
    NSLog(@"stoped publish");
}];

切换摄像头

//切换前后摄像头
[_visClient switchCamera];

释放资源

- (void) viewDidDisappear:(BOOL)animated {
    ...
    //会停止播放和发布、关闭预览
    [_visClient shutdown];
}

Edit By MaHua