Camera Controls - Android
A participant can start or stop sending their video to other participants in a meeting at any time.
This guide shows how to enable, disable and switch the webcam in a meeting.
- Enable Camera - By using
enableWebcam()function, a participant can publish camera stream to other participants. - Disable Camera - By using
disableWebcam()function, a participant can stop publishing camera stream to other participants. - Switch Camera - By using
changeWebcam()function, a participant can switch to the next camera inVideoSDK.getVideoDevices()order. To switch to a specific camera, such as the rear camera, pass itsdeviceId. If the webcam is off, it stays off, and the nextenableWebcam()uses the new camera.
Enable, Disable And Switch Webcam
These methods are suspend functions. Call them from a coroutine, such as lifecycleScope.launch (from androidx.lifecycle:lifecycle-runtime-ktx), and catch the VideoSDKException they throw when a call is refused or fails.
btnWebcam!!.setOnClickListener {
lifecycleScope.launch {
try {
// Toggle participant webcam in meeting
if (meeting!!.isWebcamEnabled) {
meeting!!.disableWebcam()
} else {
meeting!!.enableWebcam()
}
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "Webcam toggle failed: ${e.code} ${e.name}")
}
}
}
btnSwitchCamera!!.setOnClickListener {
lifecycleScope.launch {
try {
// Change Webcam in Meeting
meeting!!.changeWebcam()
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "Camera switch failed: ${e.code} ${e.name}")
}
}
}
Events
Event associated with enableWebcam():
- Every Participant will receive a callback on
onStreamEnabled()of theParticipantwithStreamobject.
Event associated with disableWebcam():
- Every Participant will receive a callback on
onStreamDisabled()of theParticipantwithStreamobject.
Events associated with changeWebcam():
- While the webcam is on, every Participant receives
onStreamDisabled()and thenonStreamEnabled(), because the webcam is turned off and on again on the new camera.
meeting!!.localParticipant.addEventListener(object : ParticipantEventListener() {
override fun onStreamEnabled(stream: Stream) {
if (stream.kind.equals("video", ignoreCase = true)) {
//participant turned on video
//Render participant video
}
}
override fun onStreamDisabled(stream: Stream) {
if (stream.kind.equals("video", ignoreCase = true)) {
//participant turned off video
//remove participant video
}
}
})
Got a Question? Ask us on discord

