Live Preview | Live Viewing | Live Interaction |
![]() |
![]() | ![]() |
StatefulWidget for displaying a single live stream room. Import it from package:tencent_live_uikit/tencent_live_uikit.dart. Playback control is managed through PlayerViewController. If you do not provide a controller, the component will automatically create and dispose its own. The UI includes full audience interaction features: stream playback, entering the room, co-hosting, live comments, gifts, and likes.import 'dart:async';import 'package:atomic_x_core/atomicxcore.dart';import 'package:flutter/material.dart';import 'package:tencent_live_uikit/tencent_live_uikit.dart';class AudiencePlayerPage extends StatefulWidget {const AudiencePlayerPage({super.key, required this.liveID});final String liveID;@overrideState<AudiencePlayerPage> createState() => _AudiencePlayerPageState();}class _AudiencePlayerPageState extends State<AudiencePlayerPage> {final PlayerViewController controller = PlayerViewController();@overridevoid initState() {super.initState();// 1. (Optional) Listen for playback status changescontroller.status.addListener(onStatusChanged);// 2. PlayerView will call controller.setLiveInfo on mount,// so startPlay / joinChannel should be called after the first frameWidgetsBinding.instance.addPostFrameCallback((_) {// 3. Start stream playbackcontroller.startPlay();// 4. Enter the live stream room. After entering, audience can send live comments, like, send gifts, and apply for co-hostingcontroller.joinChannel(completion: (LiveInfo? liveInfo, Object? error) {if (error != null) {debugPrint('joinChannel failed: $error');return;}debugPrint('joinChannel success: ${liveInfo?.liveID}');});});}void onStatusChanged() {debugPrint('player status: ${controller.status.value}');}@overridevoid dispose() {// 5. On page disposal, stop playback, leave the live stream room, and release the controllercontroller.status.removeListener(onStatusChanged);controller.stopPlay();unawaited(controller.leaveChannel());controller.dispose();super.dispose();}@overrideWidget build(BuildContext context) {return Scaffold(backgroundColor: Colors.black,body: PlayerView(// 6. Pass in live stream room info; the component will automatically call setLiveInfo internallyliveInfo: LiveInfo(liveID: widget.liveID),controller: controller,onCloseClicked: () => Navigator.of(context).maybePop(),onJoinLiveClicked: () => debugPrint('join live: ${widget.liveID}'),),);}}
import 'package:flutter/material.dart';import 'audience_player_page.dart';void enterPlayerPage(BuildContext context, String liveID) {Navigator.of(context).push(MaterialPageRoute<void>(builder: (_) => AudiencePlayerPage(liveID: liveID),fullscreenDialog: true,),);}
Property | Description |
liveInfo (required) | Live stream room information (LiveInfo). When mounted, the component automatically calls controller.setLiveInfo. |
controller | PlayerViewController, entry point for playback control. If not provided, the component creates and disposes its own controller. |
onCloseClicked | Callback when the audience clicks the close button (the component leaves the live stream room before invoking the callback). |
onJoinLiveClicked | Callback when the audience successfully enters the room via the Enter Room button. |
Method / Property | Description |
PlayerViewController() | Factory constructor for the playback controller. |
setLiveInfo(LiveInfo liveInfo) | Set live stream room information. Call before startPlay or joinChannel. When switching rooms, the component stops playback and leaves the previous room first. |
startPlay() | Start stream playback (video only, not yet entered the room). Returns immediately if liveID is empty. |
stopPlay() | Stop stream playback. |
joinChannel({PlayerJoinCompletion? completion}) | Enter the live stream room. Returns Future. The completion callback receives (LiveInfo? liveInfo, Object? error). After entering, audience can send live comments, like, send gifts, and apply for co-hosting. |
leaveChannel({PlayerLeaveCompletion? completion}) | Leave the live stream room. Returns Future. |
setVolume(int volume) | Set playback volume, range 0–100; constants are previewVolume = 0, roomVolume = 100. |
setJoinLiveEntranceEnabled(bool enabled) | Show or hide the Enter Room button. |
setContentSafeAreaInsets(EdgeInsets insets) | Set safe area insets for the component content, for adapting to notched screens and custom containers. |
status | ValueListenable, observe current playback status. |
joinInProgress | ValueListenable, indicates whether entering the room is in progress. |
liveID | ID of the currently watched live stream room. |
dispose() | Release controller resources. Call when the page is destroyed. |
Status | Description |
idle | Idle; not playing and not entered the room. |
playing | Stream playback in progress; audience has not entered the room (shows Enter Room button). |
inRoom | Audience has entered the room and can participate in live comments, likes, gifts, co-hosting, etc. |
coGuest | Co-hosting in progress (applying or already on mic seat). |
end | Live stream has ended or audience has been removed; component displays the live 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. |
PERMISSION_CAMERA=1 and PERMISSION_MICROPHONE=1 in the iOS Podfile; The iOS emulator does not have a camera. Please use the real device for local preview.피드백