Get Stream Information

The following methods provide stream-related information such as the type of the stream, media tracks, state, and so on.

Get Stream ID

The EnxStream.getId() method provides the ID of a given stream. The stream ID is used to identify a stream, be it a local or a remote stream, a canvas stream, or a screen-share stream.

Class: EnxStream

Method: public String getID()

Return: String stream Id

Sample Code

String streamID = stream.getId();

Get Stream Attributes

The EnxStream.getAttributes() method provides the stream attributes defined in the JSON payload during the stream initialization process.

Sample Code

var StreamOpt = {
"attributes": {
"name": "Stream Name",
"custom_key": "String",
"custom_key2": Number
}
}

Class: EnxStream

Method: public JSONObject getAttributes()

Return: Attributes of a stream as a JSON object.

Sample Code

JSONObject attributes = stream.getAttributes();

Verify The Availability of Media Tracks in a Stream

The EnxStream class provides the following methods to check the presence of a particular media track in a stream.

Class: EnxStream

Methods

MethodDescription
public boolean hasAudio()To check if stream has an audio track.
public boolean hasVideo()To check if stream has a video track.
public boolean hasData()To check if stream has a data track.
public boolean hasScreen()To check if stream has screen sharing.

Return: Boolean

Sample Code

if (stream.hasVideo()) {
// If the Stream has a Video Track in it.
}
// Other methods are also used in the similar manner.

Check Audio or Video Track Status in a Stream

The EnxStream class provides the following methods to verify if the current status of the audio or video track in a stream is active.

Class: EnxStream

Methods

MethodDescription
public boolean isAudioActive()To know if audio track is currently active.
public boolean isVideoActive()To know if video track is currently active.

Return: Boolean

Sample Code

if (stream.isAudioActive()) {
// If the Audio track is active in the Stream
}
if (stream.isVideoActive()) {
// If the Video track is active in the Stream
}

Know If Stream is Local or Remote

The EnxStream.ifLocal() method is used to know if the given stream is a local or a remote stream. It returns true for a local stream and false for a remote stream.

Class: EnxStream

Method: public boolean ifLocal()

Sample Code

if (stream.ifLocal()) {
// It's a Local Stream
}
else {
// It's a Remote Stream
}

Know Current State of a Stream

The EnxStream.getState() method is used to know the current state of the given Stream.

Class: EnxStream

Method: public String getState()

Returns: It returns one of the following string constants:

  • UNKNOWN
  • OPENING
  • ACTIVE
  • CLOSING
  • DESTROYED
  • LOCAL
  • BLOCKED

Sample Code

String currentState = stream.getState();

Get Media of a Stream

The EnxStream.getMedia() method provides the media stream object present in a given stream.

Class: EnxStream

Method: public MediaStream getMedia()

Return: Media Stream object

Sample Code

MediaStream mStream = stream.getMedia();

Play a Stream

You can play a local stream and all subscribed remote streams, including screen-share, and canvas streams, within EnxPlayerView Object. Therefore, you need to create an Object of EnxPlayerView Class and then attach the stream to Player View by using EnxStream.attachRenderer() method.

To stop playing a stream, detach the stream from Player View using EnxStream.detachRenderer().

Classes:

ClassDescription
EnxPlayerViewTo initiate a player view object.
EnxStreamTo attach the stream to the player view.

Method: public void attachRenderer( EnxPlayerView playerView)

ParameterDescription
playerViewTo play a stream.

Method: public void detachRenderer()

ParameterDescription
playerViewTo stop playing a stream.

Sample Code

EnxPlayerView playerView = new EnxPlayerView(
Current-Class-Context, ScalingType, mediaOverlay);
stream.attachRenderer(playerView); // Attach stream to playerview to play
yourCustomView.addView(playerView); // Add playerView to your view
stream.detachRenderer(); // Detach Renderer to stop playing