Skip to main content
Version: 0.1.x

What is SurfaceViewRender ?

SurfaceViewRender is a very powerful component of WebRTC since it is used to display the video stream on a SurfaceView. You can use SurfaceViewRender to show video of participant in your screen.

Here's the lifecycle of a SurfaceViewRenderer:

Which means:

  1. The SurfaceViewRenderer must be first initialised after being created and before it can be use at all. It starts a render thread.

  2. addSink() needs to be called when you are having VideoTrack to render. addSink is method of VideoTrack that you want to add to it. You have to pass surfaceViewRender as parameter.

  3. removeSink() should only be called when you're done showing the video. Another method of VideoTrack, and it takes the surfaceViewRenderer as a parameter.

  4. Release at last to allow the render thread to terminate. This function should be called before the activity is destroyed and/or before init it again.

Mistakes you might make and stuck :

1. Not initialised surfaceViewRender

The video never appears since a render thread was never start and you will see black view.

2. Init it again before releasing it.

If you are not releasing surfaceViewRender before calling init() again, you will get this error.

java.lang.IllegalStateException: svrParticipant Already initialized
at org.webrtc.EglRenderer.init(
3. Two videos render on same SurfaceViewRender

If you called addSink() on the same SurfaceViewRenderer for two different tracks and did not call removeSink before that, then you will see two different videos on same SurfaceViewRenderer with flickers which would look like this :

Too complicated right? However, VideoSDK makes it simple for you. You can use VideoView instead of SurfaceViewRenderer.

  • If you want to use VideoView, please update SDK version to 0.1.13 or higher.


VideoView provides a better abstraction to render live video and handles edge cases like managing init state, render more than one videos on same surfaceViewRender.


  1. addTrack(VideoTrack videoTrack) - addTrack will initialised SurfaceViewRender for you and render videoTrack that you provided.

  2. removeTrack() - removeTrack should only be called when you're done showing the video.

  3. releaseSurfaceViewRenderer() - releaseSurfaceViewRenderer should be called before the activity is destroyed.

How to use VideoView ?

// <org.webrtc.SurfaceViewRenderer
// android:id="@+id/svrParticipant"
// android:layout_width="match_parent"
// android:layout_height="match_parent" />

Initalising and adding video track
// svrParticipant.init(PeerConnectionUtils.getEglContext(), null)
// var track = stream.getTrack() as VideoTrack
// track!!.addSink(svrParticipant)

val track = stream.track as VideoTrack
// var track = stream.track as VideoTrack
// track!!.removeSink(svrParticipant);



override fun onDestroy() {

Got a Question? Ask us on discord

Was this helpful?