iOS實時視訊通話功能實現流程(實時視訊系列二)
阿新 • • 發佈:2018-12-08
ZegoVideoTalkViewController.m
// 登入成功後,房間成員開始推流
- (void)createPublishStream
{
self.publishTitle = [NSString stringWithFormat:@"Hello-%@", [ZegoSetting sharedInstance].userName];
NSString *streamID = [ZegoSetting getPublishStreamID];
NSString *logString = [NSString stringWithFormat:NSLocalizedString(@"建立流成功, streamID:%@" , nil), streamID];
[self addLogString:logString];
//建立釋出view
UIView *publishView = [self createPublishView:streamID];
if (publishView)
{
NSString *logString = [NSString stringWithFormat:NSLocalizedString(@"開始釋出直播", nil)];
[self addLogString:logString];
[self setAnchorConfig:publishView];
// 呼叫 SDK 提供的推流介面
[[ZegoManager api] startPublishing:streamID title:self.publishTitle flag:ZEGO_JOIN_PUBLISH];
}
}
// 推流成功,開始拉流,觀看房間其他成員畫面
- (void)addStreamViewContainer:(NSString *)streamID
{
if (streamID.length == 0)
return;
if (self .viewContainersDict[streamID] != nil)
return;
UIView *bigView = [[UIView alloc] init];
bigView.translatesAutoresizingMaskIntoConstraints = NO;
[self.playViewContainer addSubview:bigView];
BOOL bResult = [self setContainerConstraints:bigView containerView:self.playViewContainer viewIndex:self.viewContainersDict.count];
if (bResult == NO) {
[bigView removeFromSuperview];
return;
}
UIImage *backgroundImage = [[ZegoSetting sharedInstance] getBackgroundImage:self.view.bounds.size withText:NSLocalizedString(@"載入中", nil)];
[self setBackgroundImage:backgroundImage playerView:bigView];
self.viewContainersDict[streamID] = bigView;
// 呼叫 SDK 提供的拉流介面
bool ret = [[ZegoManager api] startPlayingStream:streamID inView:bigView];
// 設定拉流檢視模式
[[ZegoManager api] setViewMode:ZegoVideoViewModeScaleAspectFill ofStream:streamID];
}