Handle a Local Stream

The Android SDK provides the following methods to handle a local stream:

Switch Camera preview

This is to switch between Camera Feed to preview.

Class: EnxStream

Method: public void switchCameraPreview

Sample Code

stream.switchCameraPreview();

Publish a Local Stream

It is important to publish your media stream into the room for other connected users to see and communicate with you. You can continue publishing your stream until you exit, or unpublish and republish your media stream multiple times within the same session if required.

After initializing the stream, you need to publish it in the room so that other users in the room can see and hear the user on this stream.

The EnxRoom.publish() method publishes a local stream in the connected room.

Class: EnxRoom

Method: public void publish(EnxStream localStream)

Parameter

localStream: JSON Object. The initiated stream object.

Observers

ObserverDescription
onPublishedStreamAcknowledgment to the stream publisher when the stream gets published.
onStreamAddedNotification to everyone in a room when a new stream is published in the room.

Sample Code

room.publish(localStream); // To publish initialized Local Stream
public void onPublishedStream(EnxStream stream) {
// Your Stream is published
}
public void onStreamAdded(EnxStream stream) {
// Announcement of a new Stream in the Room
// You may subscribe to the Stream
}

Error Codes and Exceptions

CodeDescription
5013Failed to publish stream.
5015Unable to publish a stream without audio, video, and data.
5016Unable to publish a stream with illegible attributes.
5022Failed to publish stream because floor access not received in lecture mode room.
5023The stream has already been published.
5024Repeated publish() call while stream publishing is in process.
5025Failed to publish stream because publish() call is made on a remote stream.
1170The current subscription doesn't support the publishing of stream.

Unpublish a Local Stream

The EnxRoom.unpublish() method disconnects the local stream from the room. Unpublishing a stream does not release the device access, so subsequent republishing does not require device access permission.

Class: EnxRoom

Method: public void unpublish()

Observer

onRemoveStream: Notification to everyone in the room when a stream is removed from the room.

Sample Code

room.unpublish(); // To unpublish all Local Streams
public void onRemoveStream(EnxStream stream) {
// To announce in the room that a stream has been removed from the room.
}

Error Codes and Exceptions

CodeDescription
5029Repeated unpublish() is called when the previous unpublish request is in process.
5030Non-contextual method is called when the user tries to unpublish a stream before publishing it.

Switch Camera, Microphone, and Speaker

You may need to switch to an alternate camera, microphone, or speaker while being in a session without any break in the communication. APIs helps you achieve this seamlessly.

The following APIs allow you to switch to alternate media devices after publishing a stream, thus facilitating a switch on the fly.

Switch between Rear and Front Camera

The EnxStream.switchCamera() method allows you to switch between the rear and front camera as a source for the published stream.

Class: EnxStream

Method: public void switchCamera()

Sample Code

localStream.switchCamera();

Error Codes and Exceptions

CodeDescription
5021Unable to switch camera in audio-only call mode.
5097Unable to switch camera in a chat-only room. Non-contextual method call.

Switch to Alternate Microphone

The EnxRoom.switchMediaDevice() method switches the audio source of the published stream to an alternate microphone. This method requires the ID of the audio device to switch to, which needs to be retrieved using EnxRoom.getDevices() method.

Class: EnxRoom

Method: public void switchMediaDevice(String micDeviceId)

Parameter

micDeviceId: String. Target microphone device ID.

Observer

onNotifyDeviceUpdate: Acknowledgment sent with the new audio device ID after audio device update is complete.

Sample Code

room.switchMediaDevice( micDeviceId );
public void onNotifyDeviceUpdate( String micDeviceId ) {
// Switched to micDeviceId
}

Mute or Unmute Audio in a Stream

The EnxStream.muteSelfAudio() method is used to mute/unmute audio of your local stream.

Class: EnxStream

Method: public void muteSelfAudio( isMute )

Parameter

isMute: Boolean. Set it to true to mute audio; Set it to false to unmute audio.

Callbacks

CallbackDescription
onRemoteStreamAudioMuteNotification to everyone in the room when a user mutes self audio.
onRemoteStreamAudioUnMuteNotification to everyone in the room when a user unmutes self audio.
onAudioEventAcknowledgment to the user when self audio is muted/unmuted.

Sample Code

localStream.muteSelfAudio(true); // To mute audio of local stream
localStream.muteSelfAudio(true); // To unmute audio of local stream
// To self. Audio is muted/unmuted.
public void onAudioEvent(JSONObject json) {
// json { "result":0, "msg": "Audio Off" }
// json { "result":0, "msg": "Audio On" }
}
// To all. Audio muted by Remote user.
public void onRemoteStreamAudioMute(JSONObject json) {
// json {"result":0, "msg":"User muted audio", "clientId": "XXX" }
}
// To all. Audio unmuted by Remote user.
public void onRemoteStreamAudioUnMute(JSONObject json) {
// json {"result":0, "msg":"User unmuted audio", "clientId": "XXX" }
}

Error Codes and Exceptions

CodeDescription
5058Repeated muteSelfAudio() is called when a previous mute request is in process.
5059Repeated muteSelfAudio() is called when a previous unmute request is in process.
5060Repeated muteSelfAudio() is called after audio has been muted already.
5061Trying to unmute audio without muting it first.
5062Unable to unmute audio as audio hard-muted by the moderator.

Mute or Unmute Video in a Stream

The EnxStream.muteSelfVideo() method is used to mute/unmute the video of a local stream.

Class: EnxStream

Method: public void muteSelfVideo( isMute )

Parameter isMute: Boolean. Set it to true to mute the video; otherwise, set it to false.

Callbacks

CallbackDescription
onRemoteStreamVideoMuteNotification to everyone in the room when a user mutes self video.
onRemoteStreamVideoUnMuteNotification to everyone in the room when a user unmutes self video.
onVideoEventAcknowledgment to the user when self video is muted/unmuted.

Sample Code

localStream.muteSelfVideo(true); // To mute video of local stream
localStream.muteSelfVideo(false); // To unmute video of local stream
// To self. Video is muted/unmuted.
public void onVideoEvent(JSONObject json) {
// json { "result":0, "msg": "Video Off" }
// json { "result":0, "msg": "Video On" }
}
// To all. Video muted by Remote user
public void onRemoteStreamVideoMute(JSONObject json) {
// json {"result":0, "msg":"User muted video", "clientId": "XXX" }
}
// To all. Video unmuted by Remote user
public void onRemoteStreamVideoUnMute(JSONObject json) {
// json {"result":0, "msg":"User unmuted video", "clientId": "XXX" }
}

Error Codes and Exceptions

CodeDescription
5020Unable to process muteSelfVideo() when the user has denied camera permission.
5071Repeated muteSelfVideo() call made while a previous request is in process.
5063Repeated muteSelfVideo() call made after video has been muted already.
5064Repeated muteSelfVideo() call made after video has been unmuted already.
5065When the user tries to unmute Video without muting it first. Non-contextual method call.
5066Unable to unmute video as video hard-muted by the moderator.
5070Unable to unmute video in audio-only call mode.