Crash on joining call with remote participant video on (random) (video calling quickstart)
Closed this issue · 1 comments
iaulakh commented
Customer was facing a random crash when joining call with remote participant video on. On investigation I noticed that remoteParticipant.addOnVideoStreamsUpdatedListener(videoStreamsEventArgs -> videoStreamsUpdated(videoStreamsEventArgs));
is triggered multiple time.
To fix issue, added below code in MainActivity
.
final HashSet<String> joinedParticipants = new HashSet<>();
public void handleRemoteParticipantsUpdate(ParticipantsUpdatedEvent args) {
LinearLayout participantVideoContainer = findViewById(R.id.remotevideocontainer);
handleAddedParticipants(args.getAddedParticipants(), participantVideoContainer);
handleRemovedParticipants(args.getRemovedParticipants(), participantVideoContainer);
}
private void handleRemovedParticipants(List<RemoteParticipant> removedParticipants, LinearLayout participantVideoContainer) {
for (RemoteParticipant remoteParticipant : removedParticipants) {
if(joinedParticipants.contains(getId(remoteParticipant))) {
joinedParticipants.remove(getId(remoteParticipant));
}
}
}
public String getId(final RemoteParticipant remoteParticipant) {
final CommunicationIdentifier identifier = remoteParticipant.getIdentifier();
if (identifier instanceof PhoneNumberIdentifier) {
return ((PhoneNumberIdentifier) identifier).getPhoneNumber();
} else if (identifier instanceof MicrosoftTeamsUserIdentifier) {
return ((MicrosoftTeamsUserIdentifier) identifier).getUserId();
} else if (identifier instanceof CommunicationUserIdentifier) {
return ((CommunicationUserIdentifier) identifier).getId();
} else {
return ((UnknownIdentifier) identifier).getId();
}
}
private void handleAddedParticipants(List<RemoteParticipant> participants, LinearLayout participantVideoContainer) {
for (RemoteParticipant remoteParticipant : participants) {
if(!joinedParticipants.contains(getId(remoteParticipant))) {
joinedParticipants.add(getId(remoteParticipant));
remoteParticipant.addOnVideoStreamsUpdatedListener(videoStreamsEventArgs -> videoStreamsUpdated(videoStreamsEventArgs));
}
}
}
This issue is for a: (mark with an x
)
- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)
amendoza-msft commented
QuickStart code and readme has been updated to avoid this issue, app doesn't crash anymore.