Skip to main content
Version: 3.x.x

RTCStream Class Methods - Android

resume()​

  • resume() starts receiving a remote participant's stream again after pause() stopped it.
  • resume() is a suspend function. Call it from a coroutine.

Throws​

  • VideoSDKException with the same codes as pause(), except:
    • 3054 (ERROR_ALREADY_IN_REQUESTED_STATE) when the stream is not paused.
    • 4075 (RESUME_STREAM_FAILED) when the server refuses the request.

Returns​

  • Unit

Example​

lifecycleScope.launch {
try {
stream.resume()
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "resume() failed: ${e.code} ${e.name}")
}
}

pause()​

  • pause() stops receiving a remote participant's stream on this device, which frees that bandwidth. The participant keeps sending it to everyone else.
  • pause() is a suspend function. Call it from a coroutine.
  • Only a remote stream that this device receives can be paused. You cannot pause your own streams.

Throws​

  • VideoSDKException when the call is refused or fails:
    • 3035 (ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED) before the room is joined, or after it is left.
    • 3065 (ERROR_ROOM_RECONNECTING) while the room is reconnecting.
    • 3068 (ERROR_ACTION_NOT_SUPPORTED) for a stream this device does not receive, such as one of your own streams.
    • 3054 (ERROR_ALREADY_IN_REQUESTED_STATE) when the stream is already paused.
    • 4074 (PAUSE_STREAM_FAILED) when the server refuses the request.
    • 3079 (ERROR_OPERATION_TIMED_OUT) when the server does not answer in time.
  • 3035 and 3065 are also reported on onError().

Returns​

  • Unit

Example​

lifecycleScope.launch {
try {
stream.pause()
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "pause() failed: ${e.code} ${e.name}")
}
}

setOnStreamStateChangedListener()​

  • setOnStreamStateChangedListener() sets the listener that is told when the health of the stream changes. Use it to tell when a participant's camera is on but no picture arrives.
  • Only remote video and screen share streams report it. Audio streams never do.
  • The listener is called on the main thread. Pass null to remove it.
  • A stream that is turned off and on again is a new RTCStream, so set the listener again in every onStreamEnabled().

Parameters​

  • listener: RTCStream.OnStreamStateChangedListener? - a fun interface with one method, onStreamStateChanged(state: StreamState), so you can pass a lambda.
    • StreamState.FREEZE_DETECTED: the video stopped moving.
    • StreamState.FREEZE_RESOLVED: the video has been moving again for five seconds.
    • StreamState.STUCK: nothing has arrived for five seconds.
    • StreamState.ACTIVE: the server resumed the stream.
    • StreamState.ENDED: the server closed the stream. Nothing more arrives on it.

Returns​

  • Unit

Example​

participant.addEventListener(object : ParticipantEventListener() {
override fun onStreamEnabled(stream: RTCStream) {
if (stream.kind == MediaType.VIDEO) {
stream.setOnStreamStateChangedListener { state ->
when (state) {
StreamState.FREEZE_DETECTED, StreamState.STUCK -> Log.w("VideoSDK", "No picture from ${stream.participantId}")
StreamState.FREEZE_RESOLVED, StreamState.ACTIVE -> Log.d("VideoSDK", "Picture is back")
StreamState.ENDED -> Log.d("VideoSDK", "Stream ended")
}
}
}
}
})

Got a Question? Ask us on discord