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.
/**
* @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)
newInstanceWithToken
Initialize live streaming configuration using Token.
/**
* @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);
addButtonToBottomMenuBar
Add your custom button to the bottom menu bar. It will be displayed when the user role is equal to role
.
/**
*
* @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);
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.
public void muteAllAudioVideo();
ZegoUIKitPrebuiltLiveStreamingService.common.muteAllAudioVideo()
unMuteAllAudioVideo
This function is used in conjunction with muteAllAudioVideo
.
public void unMuteAllAudioVideo();
ZegoUIKitPrebuiltLiveStreamingService.common.unMuteAllAudioVideo()
showTopTips
Used to display messages on the ZegoUIKitPrebuiltCallFragment
.
/**
* 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);
ZegoUIKitPrebuiltLiveStreamingService.common.showTopTips(message, green)
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.
/**
*
* @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);
// 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)
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.
/**
*
* @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);
// 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)
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.
/**
*
* @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);
ZegoUIKitPrebuiltLiveStreamingService.pk.sendPKBattleRequest(anotherHostUserID, timeout, customData, callback)
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.
/**
*
* @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);
ZegoUIKitPrebuiltLiveStreamingService.pk.sendPKBattleRequest(anotherHostUserID, callback)
startPKBattleWith
After sending a PK battle request to another host and receiving their acceptance, call this API to start the PK battle.
/**
* @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);
ZegoUIKitPrebuiltLiveStreamingService.pk.startPKBattleWith(anotherHostLiveID, anotherHostUserID, anotherHostName)
stopPKBattle
Stop the PK battle.
public void stopPKBattle();
ZegoUIKitPrebuiltLiveStreamingService.pk.stopPKBattle()
cancelPKBattleRequest [1/2]
After you call sendPKBattleRequest
, you can use this method to cancel the PK battle request.
/**
* @param callback The callback for the result of canceling the invitation.
*/
public void cancelPKBattleRequest(UserRequestCallback callback);
ZegoUIKitPrebuiltLiveStreamingService.pk.cancelPKBattleRequest(callback)
cancelPKBattleRequest [2/2]
After you call sendPKBattleRequest
, you can use this method to cancel the PK battle request and pass custom data.
/**
* @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);
ZegoUIKitPrebuiltLiveStreamingService.pk.cancelPKBattleRequest(customData, callback)
acceptIncomingPKBattleRequest
When you receive a PK battle request, you can use this method to accept it.
/**
* @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);
ZegoUIKitPrebuiltLiveStreamingService.pk.acceptIncomingPKBattleRequest(requestID, anotherHostLiveID, anotherHostUser)
rejectPKBattleStartRequest
When you receive a PK battle request, you can use this method to reject it.
/**
* @param requestID The ID of the PK invitation, indicating which PK invitation to reject.
*/
void rejectPKBattleStartRequest(String requestID);
ZegoUIKitPrebuiltLiveStreamingService.pk.rejectPKBattleStartRequest(requestID)
getPKInfo
Get the current PK information. If you are not in a PK, it will return null.
public PKInfo getPKInfo();
ZegoUIKitPrebuiltLiveStreamingService.pk.getPKInfo()
getSendPKStartRequest
After calling sendPKBattleRequest
, you can use this method to get the request information.
public PKRequest getSendPKStartRequest();
ZegoUIKitPrebuiltLiveStreamingService.pk.getSendPKStartRequest()
muteAnotherHostAudio
In a PK, mute the audio of the other host.
/**
* @param mute Whether to mute the mixed audio of the other person.
* @param callback The operation result.
*/
public void muteAnotherHostAudio(boolean mute, ZegoUIKitCallback callback);
ZegoUIKitPrebuiltLiveStreamingService.pk.muteAnotherHostAudio(mute, callback)
isAnotherHostMuted
In a PK, check if the other host is muted.
public boolean isAnotherHostMuted();
ZegoUIKitPrebuiltLiveStreamingService.pk.isAnotherHostMuted()