Watch
This document mainly introduces how to use the
LiveStreamCore
module's LiveCoreView
to view the host's live stream.Prerequisites
Before using
LiveStreamCore
, you need to integrate and log in to LiveStreamCore to ensure the subsequent features work properly.Usage guide
Step 1: Adding LiveCoreView to the View
You need to first import the
LiveStreamCore
module, then create a LiveCoreView
view object and add it to your view.importLiveStreamCore
import
RTCRoomEngine
class WatchController: UIViewController {private let liveCoreView: LiveCoreView = {let view = LiveCoreView()return view}()override func viewDidLoad() {super.viewDidLoad()self.liveCoreView.registerConnectionObserver(observer: self)// Add liveCoreView to the view and set layout constraints}deinit {self.liveCoreView.unregisterConnectionObserver(observer: self)}}
public class WatchActivity extends AppCompatActivity {@Overrideprotected void onCreate(@Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);LiveCoreView liveCoreView = new LiveCoreView(this);addContentView(liveCoreView,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));}}
Step 2: Viewing
Call
joinLiveStream
to enter a host's live room for viewing.let roomId = "live_100001" // Please replace it with the room ID of the host you want to viewself.liveCoreView.joinLiveStream(roomId: roomId) { roomInfo in// Successfully joined the live streaming room} onError: { code, message in// Failed to join the live streaming room}
String roomId = "live_100001"; // Please replace it with the room ID of the host you want to viewliveCoreView.joinLiveStream(roomId, new TUIRoomDefine.GetRoomInfoCallback() {@Overridepublic void onSuccess(TUIRoomDefine.RoomInfo roomInfo) {// Successfully joined the live streaming room}@Overridepublic void onError(TUICommonDefine.Error error, String message) {// Failed to join the live streaming room}});
When the host dismisses the room, you will receive the
onRoomDismissed
callback.func onRoomDismissed(roomId: String) {// The room has been dissolved}
void onRoomDismissed(String roomId) {// The room has been dissolved}