Manage On-Screen Participants - Android
It is important that only the necessary person are present on the screen when livestream is on. To handle this, we will be using the pin
and unpin
methods of the Participant
class.
To ensure only the hosts/speakers are shown in the grid, you should use the SPOTLIGHT
layout and pin
as the priority when starting the interactive livestream.
Let us first explore two methods that we will be using to manage on-screen participants.
pin()
With these method you can pin any participant's Camera, Screen Share or both. This can be useful to identify the participants based on which you can perform rendering participant grid.
unpin()
With these methods you can unpin any participant's Camera, Screen Share or both. This can be useful to reset pin state of the participant.
Managing On-Screen Participants
- If you want to pin all the hosts/speakers automatically, you can do it by listenting to the
onMeetingJoined
callback andonParticipantModeChanged
, where you canpin
andunpin
based on the mode.
- Kotlin
- Java
private val meetingEventListener: MeetingEventListener = object : MeetingEventListener() {
override fun onMeetingJoined() {
val localParticipant = meeting!!.localParticipant
//We will pin the participant if mode is conference
if (localParticipant.mode == "CONFERENCE") {
localParticipant.pin()
} else {
localParticipant.unpin()
}
}
override fun onParticipantModeChanged(data: JSONObject) {
val localParticipant = meeting!!.localParticipant
//We will pin the participant if mode is conference else unpin him
if(localParticipant.id.equals(data.getString("peerId"))
{
if(localParticipant.mode == "CONFERENCE")
{
localParticipant.pin()
}else{
localParticipant.unpin()
}
}
}
}
override fun onCreate(savedInstanceState: Bundle?) {
//...
// add listener to meeting
meeting!!.addEventListener(meetingEventListener)
}
private final MeetingEventListener meetingEventListener = new MeetingEventListener() {
@Override
public void onMeetingJoined() {
Participant localParticipant = meeting.getLocalParticipant();
//We will pin the participant if mode is conference
if (localParticipant.getMode() == "CONFERENCE") {
localParticipant.pin();
} else {
localParticipant.unpin();
}
}
@Override
public void onParticipantModeChanged(JSONObject data) {
Participant localParticipant = meeting.getLocalParticipant();
//We will pin the participant if mode is conference else unpin him
if(localParticipant.getId().equals(data.getString("peerId"))
{
if(localParticipant.getMode() == "CONFERENCE")
{
localParticipant.pin();
}else{
localParticipant.unpin();
}
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
//...
// add listener to meeting
meeting.addEventListener(meetingEventListener);
}
- When rendering the participant grid on the Speaker side, make sure to show only the participants who are in
CONFERENCE
mode. You can filter the participants as shown in below example.
- Kotlin
- Java
private fun getSpeakerList(): List<Participant?>? {
val speakerList: MutableList<Participant?> = ArrayList()
val participants = meeting!!.participants
for (entry: Map.Entry<String, Participant> in participants.entries) {
val participant = entry.value
if (participant.mode == "CONFERENCE") {
speakerList.add(participant)
}
}
return speakerList
}
private List<Participant> getSpeakerList() {
List<Participant> speakerList = new ArrayList();
Map<String, Participant> participants = meeting.getParticipants();
for (Map.Entry<String, Participant> entry : participants.entrySet()) {
Participant participant = entry.getValue();
if (participant.getMode().equals("CONFERENCE")) {
speakerList.add(participant);
}
}
return speakerList;
}
API Reference
The API references for all the methods utilized in this guide are provided below.
Got a Question? Ask us on discord