Render Video

It all comes down to this. All the setup so far has been done so that we can show live streaming videos in our beautiful app.

To render video you will use HMSVideoView. To use it we will need few things:

  1. HMSTrack: HMSVideoView will render video using trackId from HMSTrack.
  2. HMSVideoView will use viewSize to get height and width of rendered video. If not passed, it will take whatever size is available to the widget.

How to get HMSTrack

HMSTrack is used to render video in HMSVideoView.

And you can get all tracks by listening to HMSUpdateListener.onTrackUpdate

Add a check on these tracks to see if they are video tracks or audio tracks.

For example -

/// check if track is video or audio /// For Audio track.kind == HMSTrackKind.kHMSTrackKindAudio /// For Video track.kind == HMSTrackKind.kHMSTrackKindVideo

Now, you can pass video track to HMSVideoView to get you live video on screen.

Render Video

To Render video you need the video track.

For example - HMSVideoView with HMSTrack

/// This will render video with trackId present in track and it will have height = 50 and width = 50 HMSVideoView(track: track);

Detach video to conserve bandwidth and cleanup elements

Remove the HMSVideoView from UI and it will not render its video & conserve network bandwidth.

For full example try out our Example app here.