本文档主要介绍如何使用视频直播核心组件 LiveStreamCore
模块的 LiveCoreView
实现观众连麦。
LiveCoreView
在观众连麦方面支持如下能力:
前提条件
在使用 LiveStreamCore
前,您需要先 集成与登录 LiveStreamCore ,以便后续功能正常使用。 使用指引
步骤1:将 LiveCoreView 添加到视图上
您需要先导入 LiveStreamCore
模块,然后创建一个 LiveCoreView
视图对象,并将其添加到自己的视图上。
import LiveStreamCore
import
RTCRoomEngine
class AudienceConnectionController: UIViewController {
private let liveCoreView: LiveCoreView = {
let view = LiveCoreView()
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.liveCoreView.registerConnectionObserver(observer: self)
}
deinit {
self.liveCoreView.unregisterConnectionObserver(observer: self)
}
}
public class AudienceConnectionActivity extends AppCompatActivity implements LiveCoreViewDefine.ConnectionObserver {
private LiveCoreView liveCoreView;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
liveCoreView = new LiveCoreView(this);
addContentView(liveCoreView,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
liveCoreView.registerConnectionObserver(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
liveCoreView.unregisterConnectionObserver(this);
}
}
步骤2:观众连麦
申请连麦
当您想要和某人连麦时,调用 requestIntraRoomConnection
接口,传入三个参数: 连麦的用户Id、超时时长和是否打开摄像头。
let userId = "100012"
let timeout = 30
let openCamera = true
self.liveCoreView.requestIntraRoomConnection(userId: userId, timeOut: timeout, openCamera: true) {
} onError: { code, message in
}
String userId = "anchorUserId";
int timeout = 30;
boolean openCamera = true;
liveCoreView.requestIntraRoomConnection(userId, timeout, true, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
当您是连麦被邀请方时,您会收到 onUserConnectionRequest
回调,您可调用 respondIntraRoomConnection
接口接受/拒绝连麦。
func onUserConnectionRequest(inviterUser: TUIUserInfo) {
let isAccepted = true
self.liveCoreView.respondIntraRoomConnection
(
userId
:
inviterUser
.
userId
,
isAccepted
:
isAccepted)
{
}
onError
:
{
code
,
message
in
}
}
@Override
public void onUserConnectionRequest(TUIRoomDefine.UserInfo userInfo) {
boolean isAccepted = true;
liveCoreView.respondIntraRoomConnection(userInfo.userId, isAccepted, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
}
观众主动断开连麦
当您不想和房主连麦时,调用 disconnectUser
接口即可断开连麦。
self.liveCoreView.terminateIntraRoomConnection()
liveCoreView.terminateIntraRoomConnection();
房主中断和观众连麦
当您想中断和某观众的连麦时,调用 disconnectUser
接口,传入对应用户的用户Id。
let targetUserId = "100010"
self.liveCoreView.disconnectUser(userId: targetUserId) {
} onError: { code, message in
}
String targetUserId = "100010";
liveCoreView.disconnectUser(targetUserId, new TUIRoomDefine.ActionCallback() {
@Override
public void onSuccess() {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
本页内容是否解决了您的问题?