Switch to active user on meeting with multiple participant

We have 2 different roles of users in our app which is trainers and students. We want to create a group chat session where 1 trainer and multiple students join
We have a session screen where trainers see himself as well as active speaker. We identify active speaker as meeting participant who is talking whereas this participant is not the trainer it self.

Please see following screenshot where top view is showing the trainer and down view is showing the active student.

Our Problem is catching the active speaker.

We noticed that this function is not triggering when someone speaks during the session: onActiveSpeakerVideoUserChanged
So we implemented following function which causes flickering on student view.

We seek assistance either how to use onActiveSpeakerVideoUserChanged or fixing the below functionality or any other suggestions.

    mHandler.postDelayed({
        if(mInMeetingService!= null && mInMeetingService!!.inMeetingVideoController!= null && mInMeetingService!!.inMeetingVideoController.activeVideoUserID() != null)
        {
            Log.d("HandlerActiveUser " , mInMeetingService!!.inMeetingVideoController.activeVideoUserID().toString())

            val renderInfo = MobileRTCVideoUnitRenderInfo(0, 0, 100, 100)
            renderInfo.aspect_mode = MobileRTCVideoUnitAspectMode.VIDEO_ASPECT_PAN_AND_SCAN

            if(mInMeetingService!!.getUserInfoById(mInMeetingService!!.inMeetingVideoController.activeVideoUserID())!= null) {
                val activeUser =
                    mInMeetingService!!.getUserInfoById(mInMeetingService!!.inMeetingVideoController.activeVideoUserID())

                zoomClientVideoView.videoViewManager.removeAllAttendeeVideoUnit()
                zoomClientVideoView.videoViewManager.addAttendeeVideoUnit(
                    mInMeetingService!!.inMeetingVideoController.activeVideoUserID(),
                    renderInfo
                )

                UpdateAttendeeInfo(activeUser)
            }
        }

        checkActiveUser()
    }, 1000)

}

Hi hardc0der,

Thanks for the post. The onActiveSpeakerVideoUserChanged is mostly used for drawing the green border for active speakers, but the active speaker and the active video might not be the same person in some cases, for example, when someone does not turn on the camera but speaking. You may leverage the callback onActiveVideoUserChanged for your scenario, which will be triggered when someone is speaking, and the userId will be the current active video user(which might not be the active speaker).

Hope this helps. Thanks!