Create a Local Stream

The Android SDK provides the getLocalStream() method to create a local stream. This method initializes a local stream at the client endpoint before publishing it to a virtual room.

Initiate a Local Stream

The EnxRoom.getLocalStream() method initializes a local stream at the client endpoint before publishing it to the room. The initialization process comprises of specifying media tracks, adding custom attributes, and so on in the form of a JSON object, which is passed as a parameter to the method.

Class: EnxRoom

Method: public EnxStream getLocalStream( JSONObject publishStreamInfo )

Parameter publishStreamInfo: JSON Object. A JSON object with local stream options as shown in the below sample code.

Sample Code

{
"audio": true, // Whether to add Audio to stream
"video": true, // Whether to add Video to stream
"data": true, // Whether to add Data to stream
"videoSize": { // Video Frame Size - Deprecated in Android SDK v2.0.1+
"minWidth": number,
"minHeight": number,
"maxWidth": number,
"maxHeight": number
),
"audioMuted": true, // Audio muted on entry to room
"videoMuted": true, // Video muted on entry to room
"attributes": { // Object to carry custom data
"custom1": ""
},
"maxVideoBW": number, // Max Bandwidth - Deprecated in Android SDK v2.0.1+
"minVideoBW": number // Min Bandwidth - Deprecated in Android SDK v2.0.1+
}

Error Codes and Exceptions

CodeDescription
5015Failed to initialize the stream without audio, video, and data track.
5016Failed to initialize the stream due to incorrect values of JSON keys in publishStreamInfo.
5017Unable to create a stream due to failure to access camera and microphone.
5018Unable to create a video stream due to failure to access camera. Only audio stream is created.
5019Unable to create a stream due to failure to access microphone.
5084Invalid video layer. A maximum of 3 layers is allowed.
5088Invalid frame rate. A maximum of 30 frame rate is allowed.

Initiate a Stream with Multiple Video Layers

To help stream subscribers receive the best video quality subject to the available bandwidth, stream publishers must ensure that their streams carry many video layers of different quality. The Auto Bandwidth Detection feature detects the subscriber's bandwidth and switches to the respective video layer for a smooth video experience.

Sample Code

JSONObject streamOpt = {
audio: true,
video: true,
maxVideoLayers: 3 // Carry 3 layers, viz HD 720p, SD 480p & LD 240p/180p
};
// Enumerated Values for maxVideoLayers: 1, 2, 3
// 1=HD 720p layer only
// 2=HD 720p & SD 480p layers only
// 3=HD 720p, SD 480p & LD 240p/180p layers
EnxStream localStream = room.getLocalStream(streamOpt);

Error Codes and Exceptions

CodeDescription
5084Illegible value for maxVideoLayers. A maximum of 3 layers of video are supported.