Creating a Room - Android
initialize()
Call VideoSDK.initialize() before you create a room.
Call it once, for example in Application.onCreate(). Later calls do nothing.
Parameters
- context: Context
Returns
Unit
fun initialize(context: Context)
createRoom()
createRoom()returns a newRoomfor you to join.- Only
roomIdandtokenare required. Pass the other arguments by name. - Nothing is sent to the server until you call
join()on the returned room. VideoSDK.initialize()must have run first, or it throwsIllegalStateException.- Only one room at a time: a second
createRoom()takes over from the first.
fun createRoom(
roomId: String,
token: String,
participantName: String? = null,
micEnabled: Boolean = true,
camEnabled: Boolean = true,
participantId: String? = null,
mode: Mode? = null,
multiStream: Boolean? = null,
customCameraTrack: CustomStreamTrack? = null,
customMicrophoneTrack: CustomStreamTrack? = null,
metaData: JSONObject? = null,
signalingBaseUrl: String? = null,
preferredProtocol: PreferredProtocol? = null,
codecSwitchEnabled: Boolean = true,
enableBatching: Boolean = true,
translationLanguage: String? = null,
speakingLanguage: String? = null,
maxResolution: MaxResolution? = null,
defaultCamera: FacingMode = FacingMode.front,
autoConsume: Boolean = true,
dynaCast: Boolean = false,
): Room
Parameters
roomId
-
Unique Id of the room where that participant will be joining.
- type :
String REQUIRED
- type :
To create a room, see the Create Room API.
An empty roomId throws VideoSDKException with code 3073 (ERROR_INVALID_PARAMETER).
token
-
The authentication token, generated on your server with your VideoSDK API key and secret.
- type :
String REQUIRED
- type :
To generate a token, see Authentication.
An empty token throws VideoSDKException with code 3073 (ERROR_INVALID_PARAMETER). A malformed or expired token is not checked here: the server rejects it when you call join().
participantName
-
Name of the participant who will be joining the room. This name is displayed to the other participants. If it is
nullor empty, the participant joins with a random 6-character name.- type :
String? - default:
null OPTIONAL
- type :
micEnabled
-
Whether the
micof the participant will be on while joining the room. If it is set tofalse, the mic of that participant will bedisabledby default, but can beenabledordisabledlater. -
The
RECORD_AUDIOpermission must already be granted, or the mic does not start.- type:
Boolean - default:
true OPTIONAL
- type:
camEnabled
-
Whether the camera of the participant will be on while joining the room. If it is set to
false, the camera of that participant will bedisabledby default, but can beenabledordisabledlater. -
The
CAMERApermission must already be granted, or the camera does not start and the error is reported ononError.- type:
Boolean - default:
true OPTIONAL
- type:
participantId
-
Unique Id of the participant. If you pass
nullor an empty string, the SDK creates an Id by itself and uses it.- type :
String? - default:
null OPTIONAL
- type :
mode
There are three modes available:
-
Mode.SEND_AND_RECV: In this mode, the participant sends and receives audio and video. -
Mode.SIGNALLING_ONLY: In this mode, the participant neither sends nor receives audio or video, but stays in the room. -
Mode.RECV_ONLY: In this mode, the participant receives audio and video but sends none.
Mode is in the live.videosdk.rtc.android.lib package.
- type:
Mode? - default:
null, which usesMode.SEND_AND_RECV OPTIONAL
multiStream
-
If
true, the camera is sent as several resolution layers, so each viewer can receive the layer its connection can carry. Iffalse, it is sent as a single layer.- type:
Boolean? - default:
null, which usestrue OPTIONAL
- type:
customCameraTrack
-
A camera track from
createCameraVideoTrack()to publish instead of the default camera.- type :
CustomStreamTrack? - default:
null, which uses the default camera OPTIONAL
- type :
customMicrophoneTrack
-
A microphone track from
createMicrophoneAudioTrack()to publish instead of the default mic.- type :
CustomStreamTrack? - default:
null, which uses the default mic OPTIONAL
- type :
See Custom Tracks.
metaData
-
Extra details about this participant, such as a profile image URL. Every participant, you included, can read it from that participant's
metaDataproperty, for exampleroom.localParticipant.metaData.- type:
JSONObject? - default:
null OPTIONAL
- type:
signalingBaseUrl
-
The base URL of your proxy server, if you route signaling through one.
- type:
String? - default:
null, which uses the VideoSDK signaling server OPTIONAL
- type:
If you intend to use a proxy server with VideoSDK, let us know first at support@videosdk.live.
If your proxy already works with Android SDK 2.x, contact support before you upgrade. Android SDK 3.0.0 fetches its configuration from a different path on the proxy than 2.x did.
preferredProtocol
- The network protocol to prefer for media:
-
UDP_ONLY: lowest latency, but no connection on a network that blocks UDP. -
UDP_OVER_TCP: UDP, falling back to TCP when UDP can't get through. -
TCP_ONLY: works on restrictive corporate networks, at the cost of latency. -
type:
VideoSDK.PreferredProtocol? -
default:
null, which usesUDP_OVER_TCP -
OPTIONAL
-
codecSwitchEnabled
-
If
true, the video codec you send switches to VP8 when a remote participant cannot decode it, andonCodecChangedis called on yourRoomEventListener.- type:
Boolean - default:
true OPTIONAL
- type:
enableBatching
-
If
true, notifications from the server are received in batches.- type:
Boolean - default:
true OPTIONAL
- type:
translationLanguage
-
The language this participant receives live translations in, as a language code such as
"en". If it isnull, translation is off. -
To switch language once translation has started, call
changeTranslationLanguage(). It throwsVideoSDKExceptionwith code4044(CHANGE_TRANSLATION_LANGUAGE_FAILED) if the server refuses, for example before translation has started.- type:
String? - default:
null OPTIONAL
- type:
speakingLanguage
-
The language this participant speaks, as a language code such as
"en".- type:
String? - default:
null OPTIONAL
- type:
maxResolution
-
The size the default camera opens at.
MaxResolution.hdopens it at 1280x720.MaxResolution.sdopens it at 960x540, or the largest 16:9 size below it that the camera offers. -
A track passed as
customCameraTrackkeeps its ownencoderConfig.- type:
MaxResolution? - default:
null, which usesMaxResolution.hd OPTIONAL
- type:
defaultCamera
-
The camera the default camera track opens on:
FacingMode.frontorFacingMode.back. -
A track passed as
customCameraTrackkeeps its ownfacingMode.- type:
FacingMode - default:
FacingMode.front OPTIONAL
- type:
autoConsume
-
If
true, the mic and camera of every remote participant are received as soon as they publish them. -
If
false, a participant's mic and camera are not received until you callconsumeMicStreams()orconsumeWebcamStreams()on thatParticipant. This saves bandwidth in large rooms. Screen shares have no consume call. The consume methods take effect only when the room was created withautoConsumeset tofalse. See Selective Subscription.- type:
Boolean - default:
true OPTIONAL
- type:
dynaCast
-
If
true, the server lowers the quality of the camera stream you send while no one is watching its larger layers, and raises it again when someone is. This saves upload bandwidth. -
It has no effect on a camera that sends a single layer:
multiStreamoff, or a codec other than VP8.- type:
Boolean - default:
false OPTIONAL
- type:
Returns
room
createRoom()returns a newRoominstance.
Throws
IllegalStateExceptionifVideoSDK.initialize()has not run.VideoSDKExceptionwith code3073(ERROR_INVALID_PARAMETER) ifroomIdortokenis empty.
Example
VideoSDK.initialize(applicationContext)
// Create the room with the token generated on your server
val room = VideoSDK.createRoom(
roomId = "abc-1234-xyz",
token = token,
participantName = "John Doe",
micEnabled = true,
camEnabled = true,
multiStream = false,
)
// Register your listener, then join from a coroutine
room.addEventListener(roomEventListener)
lifecycleScope.launch {
try {
room.join()
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "Join failed: ${e.code} ${e.name}")
}
}
Got a Question? Ask us on discord

