Live Preview | Live Viewing | Live Interaction |
![]() |
![]() | ![]() |
TUILiveKit trial version or activate the paid version.PlayerView, please ensure that you have logged in; otherwise, the flow pulling and room entry will fail.UIBackgroundModes → audio) That is, Target → Signing & Capabilities → Background Modes → Audio, AirPlay, and Picture in Picture. When not declared, the App will be suspended by the system when entering the background, and the audience will not be able to hear the sound from the live stream.import AtomicXCoreimport Combineimport SnapKitimport TUILiveKitimport UIKitclass AudiencePlayerViewController: UIViewController {private let liveID: Stringprivate let playerView = PlayerView()private var cancellables = Set<AnyCancellable>()init(liveID: String) {self.liveID = liveIDsuper.init(nibName: nil, bundle: nil)}@available(*, unavailable)required init?(coder: NSCoder) {fatalError("init(coder:) has not been implemented")}override func viewDidLoad() {super.viewDidLoad()// 1. Add playerView to the viewview.addSubview(playerView)playerView.snp.makeConstraints { make inmake.edges.equalToSuperview()}// 2. Set live stream room info (must be called before startPlay / joinChannel)let liveInfo = LiveInfo()liveInfo.liveID = liveIDplayerView.setLiveInfo(liveInfo)playerView.contentSafeAreaInsets = view.safeAreaInsets// 3. Listen for close and enter room eventsplayerView.onCloseClicked = { [weak self] inself?.dismiss(animated: true)}playerView.onJoinLiveClicked = { [weak self] inprint("onJoinLiveClicked, liveID:\\(self?.liveID ?? "")")}// 4. (Optional) Listen for playback status changesplayerView.status.receive(on: DispatchQueue.main).sink { status inprint("player status:\\(status)")}.store(in: &cancellables)// 5. Start streaming playbackplayerView.startPlay()// 6. Enter the live stream room. After entering, audience can send live comments, likes, gifts, and request co-hosting.playerView.joinChannel { result inswitch result {case .success(let joinedLiveInfo):print("joinChannel success, liveID:\\(joinedLiveInfo.liveID)")case .failure(let error):print("joinChannel failed:\\(error.localizedDescription)")}}}override func viewDidDisappear(_ animated: Bool) {super.viewDidDisappear(animated)// 7. Stop playback and leave the live stream room when leaving the pageguard isMovingFromParent || isBeingDismissed else { return }playerView.stopPlay()playerView.leaveChannel(completion: nil)}}
// Navigate to the "Single Live Stream Room" viewing pagelet playerVC = AudiencePlayerViewController(liveID: "Your live stream room id")playerVC.modalPresentationStyle = .fullScreenpresent(playerVC, animated: false)
Method / Property | Description |
PlayerView() | Constructor for creating the viewing component. |
setLiveInfo(_ liveInfo: LiveInfo) | Set live stream room information. Must be called before startPlay and joinChannel; otherwise, these APIs will return immediately due to missing room info. |
startPlay() | Start streaming playback (plays video only, not yet entered the room). |
stopPlay() | Stop streaming playback. |
joinChannel(completion:) | Enter the live stream room. Callback returns Result. After entering, audience can send live comments, likes, gifts, and request co-hosting. |
leaveChannel(completion:) | Leave the live stream room. Callback returns Result. |
setVolume(_ volume: Int) | Set playback volume, range 0 ~ 100. |
joinLiveEntranceEnabled | Whether to show the Enter Room entrance. If disabled, audience can watch the stream directly and only enter the room after clicking the entrance. |
contentSafeAreaInsets | Safe area insets for the component content, used for adapting to notched screens and custom containers. |
status | AnyPublisher (Combine), used to observe current playback status. |
liveID | ID of the current live stream room being watched. |
onCloseClicked | Closure callback triggered when audience clicks the close button (component will leave the room before callback). |
onJoinLiveClicked | Closure callback triggered when audience successfully enters the room via the Enter Room entrance. |
Status | Description |
idle | Idle, not playing and not entered the room. |
playing | Streaming playback in progress, audience not yet entered the room (shows Enter Room entrance). |
inRoom | Entered the room, audience can participate in live comments, likes, gifts, co-hosting, etc. |
coGuest | Co-hosting in progress (requesting or already on mic seat). |
end | Live stream has ended or was kicked out, component displays the end page. |
Feature | Description | Integration Guide |
Host Streaming | The complete workflow for a host to start a stream, including pre-stream setup and various in-stream interactions. | |
Live Stream List | Display the live stream list interface and features, including the live stream list and room information display. | |
Gift System | Support custom gift asset configuration, billing system integration, and gift-sending in PK scenarios. |

フィードバック