logo
On this page

API

ZegoUIKitPrebuiltLiveStreamingFragment

The live streaming component. You can add this Fragment to any Activity in your project to integrate live streaming functionality.

newInstance

Initialize the live streaming configuration with the AppSign.

Prototype
/**
 * @param appID    You can create a project and obtain the appID from the [ZEGOCLOUD Console](https://console.zegocloud.com/account/).
 * @param appSign  You can create a project and obtain the appSign from the [ZEGOCLOUD Console](https://console.zegocloud.com/account/).
 * @param userID   The ID of the current logged-in user. It can be any valid string. Typically, you can use the ID from your own user system.
 * @param userName The name of the current logged-in user. It can be any valid string. Typically, you can use the name from your own user system.
 * @param liveID   The ID of the live streaming. This ID is the unique identifier for the current live streaming, so you need to ensure its uniqueness. It can be any valid string. Users with the same liveID will join the same live streaming room.
 * @param config   The configuration used to initialize the live streaming.
 * @return
 */
public static ZegoUIKitPrebuiltLiveStreamingFragment newInstance(long appID, @NonNull String appSign, @NonNull String userID, @NonNull String userName, @NonNull String liveID, @NonNull ZegoUIKitPrebuiltLiveStreamingConfig config) 
1
Copied!

newInstanceWithToken

Initialize live streaming configuration using Token.

Prototype
/**
 * @param appID    You can create a project and obtain the AppID in the [ZEGOCLOUD Console](https://console.zegocloud.com/account/).
 * @param token    You can create a project and obtain the ServerSecret in the [ZEGOCLOUD Console](https://console.zegocloud.com/account/), and then generate a Token on your server to avoid leaking your AppSign.
 * @param userID   The ID of the currently logged-in user. It can be any valid string. Typically, you would use the ID from your own user system.
 * @param userName The name of the currently logged-in user. It can be any valid string. Typically, you would use the name from your own user system.
 * @param liveID   The ID of the live streaming. This ID is the unique identifier for the current live streaming, so you need to ensure its uniqueness. It can be any valid string. Users with the same liveID will join the same live streaming room.
 * @param config   The configuration used to initialize the live streaming.
 * @return
 */
public static ZegoUIKitPrebuiltLiveStreamingFragment newInstanceWithToken(long appID, @NonNull String token, @NonNull String userID, @NonNull String userName, @NonNull String liveID, @NonNull ZegoUIKitPrebuiltLiveStreamingConfig config);
1
Copied!

addButtonToBottomMenuBar

Add your custom button to the bottom menu bar. It will be displayed when the user role is equal to role.

Prototype
/**
 *
 * @param viewList The list of custom buttons to be added.
 * @param role The corresponding role to which the custom button will be added for display.
 */
public void addButtonToBottomMenuBar(List<View> viewList, ZegoLiveStreamingRole role);
1
Copied!

ZegoUIKitPrebuiltLiveStreamingService

Common

The interface and events for general co-hosting, excluding PK-related interfaces and events.

muteAllAudioVideo

Mutes all audio and video. If you want your application to stop audio and video when it goes to the background, you can use this interface, and then use unMuteAllAudioVideo to restore audio and video when the application returns to the foreground.

Prototype
Example
public void muteAllAudioVideo();
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.common.muteAllAudioVideo()
1
Copied!

unMuteAllAudioVideo

This function is used in conjunction with muteAllAudioVideo.

Prototype
Example
public void unMuteAllAudioVideo();
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.common.unMuteAllAudioVideo()
1
Copied!

showTopTips

Used to display messages on the ZegoUIKitPrebuiltCallFragment.

Prototype
Example
/**
 *  Display a message at the top.
 * @param message  The content of the message.
 * @param green  The color of the message, either green or red. true for green, false for red.
 */
public void showTopTips(String message, boolean green);
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.common.showTopTips(message, green)
1
Copied!

sendInRoomMessage

Send a broadcast message to the room. Users who have logged into the same room will receive the message. The message is reliable and will be displayed in the lower left corner of the live streaming room. In addition to the interface callback, you can also use ZegoUIKitPrebuiltLiveStreamingService.common.events.addInRoomMessageReceivedListener to listen for events of sending and receiving room messages.

Prototype
Example
/**
 * 
 * @param message The content of the message sent in the room.
 * @param listener The listener for the result status of sending the message in the room.
 */
public void sendInRoomMessage(String message, ZegoInRoomMessageSendStateListener listener);
1
Copied!
// Add a listener to get messages from others.
ZegoUIKitPrebuiltLiveStreamingService.common.events.addInRoomMessageReceivedListener(inRoomMessageListener)
// Send a message to others when needed
ZegoUIKitPrebuiltLiveStreamingService.common.sendInRoomMessage(message, listener)
1
Copied!

sendBarrageMessage

Send barrage messages in the room, usually used in scenarios where there is a large amount of message exchange in the room and message reliability is not required, such as live streaming barrage. In addition to the interface callback, you can also use ZegoUIKitPrebuiltLiveStreamingService.common.events.addBarrageMessageListener to listen for the sending and receiving events of room messages.

Prototype
Example
/**
 * 
 * @param message The content of the barrage message sent in the room.
 * @param listener The result status listener for sending barrage messages in the room.
 */
public void sendBarrageMessage(String roomID, String message, IZegoIMSendBarrageMessageCallback listener);
1
Copied!
// Add a listener to get messages from others
ZegoUIKitPrebuiltLiveStreamingService.common.events.addBarrageMessageListener(barrageMessageListener)
// Send messages to others when needed
ZegoUIKitPrebuiltLiveStreamingService.common.sendBarrageMessage(roomid, message, listener)
1
Copied!

PK

APIs and events related to PK battles.

sendPKBattleRequest [1/2]

Send a request to anotherHostUserID for a PK battle and pass custom data. The receiver can use ZegoUIKitPrebuiltLiveStreamingService.pk.events.addPKListener to listen for PK battle events. When a PK battle request is received, the onIncomingPKBattleRequestReceived event will be triggered.

Prototype
Example
/**
 * 
 * @param anotherHostUserID The UserID of the other host participating in the PK battle.
 * @param timeout The timeout duration.
 * @param customData Custom data to be passed.
 * @param callback The callback to listen for the result of the invitation.
 */
public void sendPKBattleRequest(String anotherHostUserID, int timeout, String customData, UserRequestCallback callback); 
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.sendPKBattleRequest(anotherHostUserID, timeout, customData, callback)
1
Copied!

sendPKBattleRequest [2/2]

Send a request to anotherHostUserID for a PK battle. The receiver can use ZegoUIKitPrebuiltLiveStreamingService.pk.events.addPKListener to listen for PK battle events. When a PK battle request is received, the onIncomingPKBattleRequestReceived event will be triggered.

Prototype
Example
/**
 * 
 * @param anotherHostUserID The UserID of the other host participating in the PK battle.
 * @param callback The callback to listen for the result of the invitation.
 */
public void sendPKBattleRequest(String anotherHostUserID, UserRequestCallback callback);
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.sendPKBattleRequest(anotherHostUserID, callback)
1
Copied!

startPKBattleWith

After sending a PK battle request to another host and receiving their acceptance, call this API to start the PK battle.

Prototype
Example
/**
 * @param anotherHostLiveID The Live stremain ID of the other host participating in the PK battle.
 * @param anotherHostUserID The UserID of the other host participating in the PK battle.
 * @param anotherHostName The name of the other host participating in the PK battle.
 */
public void startPKBattleWith(String anotherHostLiveID, String anotherHostUserID, String anotherHostName);
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.startPKBattleWith(anotherHostLiveID, anotherHostUserID, anotherHostName)
1
Copied!

stopPKBattle

Stop the PK battle.

Prototype
Example
public void stopPKBattle();
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.stopPKBattle()
1
Copied!

cancelPKBattleRequest [1/2]

After you call sendPKBattleRequest, you can use this method to cancel the PK battle request.

Prototype
Example
/**
 * @param callback The callback for the result of canceling the invitation.
 */
public void cancelPKBattleRequest(UserRequestCallback callback);
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.cancelPKBattleRequest(callback)
1
Copied!

cancelPKBattleRequest [2/2]

After you call sendPKBattleRequest, you can use this method to cancel the PK battle request and pass custom data.

Prototype
Example
/**
 * @param customData Custom data to be passed.
 * @param callback The callback for the result of canceling the invitation.
 */
public void cancelPKBattleRequest(String customData, UserRequestCallback callback);
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.cancelPKBattleRequest(customData, callback)
1
Copied!

acceptIncomingPKBattleRequest

When you receive a PK battle request, you can use this method to accept it.

Prototype
Example
/**
 * @param requestID The ID of the PK invitation, indicating which PK invitation to accept.
 * @param anotherHostLiveID The live streaming ID of the other host who participates in the PK battle.
 * @param anotherHostUser The information of the other host who participates in the PK battle.
 */
public void acceptIncomingPKBattleRequest(String requestID, String anotherHostLiveID, ZegoUIKitUser anotherHostUser);
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.acceptIncomingPKBattleRequest(requestID, anotherHostLiveID, anotherHostUser)
1
Copied!

rejectPKBattleStartRequest

When you receive a PK battle request, you can use this method to reject it.

Prototype
Example
/**
 * @param requestID The ID of the PK invitation, indicating which PK invitation to reject.
 */
void rejectPKBattleStartRequest(String requestID);
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.rejectPKBattleStartRequest(requestID)
1
Copied!

getPKInfo

Get the current PK information. If you are not in a PK, it will return null.

Prototype
Example
public PKInfo getPKInfo();
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.getPKInfo()
1
Copied!

getSendPKStartRequest

After calling sendPKBattleRequest, you can use this method to get the request information.

Prototype
Example
public PKRequest getSendPKStartRequest();
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.getSendPKStartRequest()
1
Copied!

muteAnotherHostAudio

In a PK, mute the audio of the other host.

Prototype
Example
/**
 * @param mute Whether to mute the mixed audio of the other person.
 * @param callback The operation result.
 */
public void muteAnotherHostAudio(boolean mute, ZegoUIKitCallback callback);
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.muteAnotherHostAudio(mute, callback)
1
Copied!

isAnotherHostMuted

In a PK, check if the other host is muted.

Prototype
Example
public boolean isAnotherHostMuted();
1
Copied!
ZegoUIKitPrebuiltLiveStreamingService.pk.isAnotherHostMuted()
1
Copied!