CometChat Calls SDK v5 — Video Controls
Overview
Programmatically control the local camera (pause/resume) and switch between front/back cameras during an active call.
Key Imports
import com.cometchat.calls.core.CallSession
import com.cometchat.calls.model.CameraFacing
import com.cometchat.calls.listeners.MediaEventsListener
Implementation
Pause / Resume Video
val callSession = CallSession.getInstance()
callSession.pauseVideo() // turn off camera
callSession.resumeVideo() // turn on camera
Switch Camera
callSession.switchCamera() // toggle front ↔ back
Listen for Video Events
callSession.addMediaEventsListener(this, object : MediaEventsListener() {
override fun onVideoPaused() {
// Update video button to "off" state, show avatar
}
override fun onVideoResumed() {
// Update video button to "on" state, show video
}
override fun onCameraFacingChanged(facing: CameraFacing) {
when (facing) {
CameraFacing.FRONT -> { /* front camera active */ }
CameraFacing.REAR -> { /* rear camera active */ }
}
}
// ... other required overrides
override fun onAudioMuted() {}
override fun onAudioUnMuted() {}
override fun onRecordingStarted() {}
override fun onRecordingStopped() {}
override fun onAudioModeChanged(audioMode: AudioMode) {}
})
Initial Video Settings (Pre-Session)
val sessionSettings = CometChatCalls.SessionSettingsBuilder()
.setSessionType(SessionType.VIDEO)
.startVideoPaused(false) // start with camera on
.setInitialCameraFacing(CameraFacing.FRONT) // start with front camera
.hideToggleVideoButton(false) // show video toggle
.hideSwitchCameraButton(false) // show camera switch
.build()
Gotchas
pauseVideo()/resumeVideo()only work during an active sessionswitchCamera()toggles between front and back — no parameter neededCameraFacingenum:FRONT,REAR- For voice calls (
SessionType.VOICE), set.startVideoPaused(true) - Camera permissions must be granted at runtime before joining
Sample App Reference
CallActivity.kt— SetsstartVideoPaused(true)for voice calls