VideoView

class VideoView : SurfaceViewRenderer

A view component for rendering video tracks from participants.

VideoView extends SurfaceViewRenderer and provides a simplified API for attaching and detaching VideoTracks. It handles initialization, track management, and cleanup automatically.

Use this view in your XML layouts or create it programmatically, then call addTrack to start rendering and removeTrack to stop.

Code Example:


// In XML:
// <live.videosdk.rtc.android.VideoView
//     android:id="@+id/videoView"
//     android:layout_width="match_parent"
//     android:layout_height="match_parent" />

// In code:
val videoView = findViewById<VideoView>(R.id.videoView)

participant.addEventListener(object : ParticipantEventListener() {
    override fun onStreamEnabled(stream: Stream) {
        if (stream.kind.equals("video", ignoreCase = true)) {
            val videoTrack = stream.track as VideoTrack
            videoView.addTrack(videoTrack)
        }
    }

    override fun onStreamDisabled(stream: Stream) {
        if (stream.kind.equals("video", ignoreCase = true)) {
            videoView.removeTrack()
        }
    }
})

See also

Stream.getTrack()

Constructors

Link copied to clipboard
constructor(context: Context)
Creates a new VideoView with the given context.
constructor(context: Context, attrs: AttributeSet)
Creates a new VideoView with the given context and attribute set.

Functions

Link copied to clipboard
fun addTrack(videoTrack: VideoTrack)
This method can be used to attach a VideoTrack to this view for rendering.
fun addTrack(videoTrack: VideoTrack, rendererEvents: RendererCommon.RendererEvents)
This method can be used to attach a VideoTrack to this view for rendering with renderer event callbacks.
Link copied to clipboard
This method can be used to release the surface view renderer and free associated resources.
Link copied to clipboard
This method can be used to detach the currently attached video track from this view.
Link copied to clipboard
fun setMirror(mirror: Boolean)
This method can be used to mirror the rendered video horizontally.
Link copied to clipboard
fun setScalingType(scalingType: RendererCommon.ScalingType)
This method can be used to set the scaling type for how the video frame fits within the view.