Skip to main content
Version: 3.x.x

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.

  1. Enable Camera - By using enableWebcam() function, a participant can publish camera stream to other participants.
  2. Disable Camera - By using disableWebcam() function, a participant can stop publishing camera stream to other participants.
  3. Switch Camera - By using changeWebcam() function, a participant can switch to the next camera in VideoSDK.getVideoDevices() order. To switch to a specific camera, such as the rear camera, pass its deviceId. If the webcam is off, it stays off, and the next enableWebcam() 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():

Event associated with disableWebcam():

Events associated with changeWebcam():

  • While the webcam is on, every Participant receives onStreamDisabled() and then onStreamEnabled(), 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