本文档主要介绍如何使用 SeatGridView
收听某主播的直播。
前提条件
在使用 SeatGridView
前,您需要先 集成与登录 SeatGridView ,以便后续功能正常使用。 使用指引
步骤1:将 SeatGridView 添加到视图上
您需要先导入 SeatGridView
模块,然后创建一个 SeatGridView 视图对象,并将其添加到自己的视图上。
import SeatGridView
import RTCRoomEngine
class ListenController: UIViewController {
private let seatGridView: SeatGridView = {
let view = SeatGridView()
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.seatGridView.addObserver(observer: self)
}
deinit {
self.seatGridView.removeObserver(observer: self)
}
}
import com.trtc.uikit.livekit.seatGridView.SeatGridView;
public class ListenActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SeatGridView seatGridView = new SeatGridView(this);
addContentView(seatGridView,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}
}
步骤2:收听
调用 joinVoiceRoom
进入某主播的直播间进行收听。
let roomId = "voice_100001"
self.seatGridView.joinVoiceRoom(roomId: roomId) { roomInfo in
} onError: { code, message in
}
String roomId = "live_100001";
seatGridView.joinVoiceRoom(roomId, new TUIRoomDefine.GetRoomInfoCallback() {
@Override
public void onSuccess(TUIRoomDefine.RoomInfo roomInfo) {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
当您想要退出直播间时,可调用 leaveVoiceRoom 接口。
self.seatGridView.leaveVoiceRoom {
} onError: { code, message in
}
seatGridView.leaveVoiceRoom( new , new TUIRoomDefine.GetRoomInfoCallback() {
@Override
public void onSuccess(TUIRoomDefine.RoomInfo roomInfo) {
}
@Override
public void onError(TUICommonDefine.Error error, String message) {
}
});
当房主解散房间时,您会收到 onRoomDismissed
回调。
func onRoomDismissed(roomId: String) {
}
void onRoomDismissed(String roomId) {
}
本页内容是否解决了您的问题?