Video

You can programmatically control user video for an ongoing session using the methods provided by the Video SDK.

Note: Prior to using video, you will need to request permissions to use the camera. More info on how to obtain these permissions can be found here. The required Android permissions are CAMERA.

Video controls

Using the SDK functions, users in a session can be provided with controls for managing their video. Session hosts can manage their own video as well the video of other users in the session.

Some common features that you might want to include in your app could be an option to enable or disable a user's video. Prior to changing the video control, you may also need to obtain data about the state of each users' present it in the UI of your app.

The following are some examples that you can refer to when implementing features related to video controls.

Display or hide a user's video

Video can be controlled on a per-user basis. First, you should check the current video status of the user.

val isVideoOn = user.videoCanvas.videoStatus.isOn
boolean isVideoOn = user.getVideoCanvas().getVideoStatus().isOn();

If the user's video is not already enabled, you can start displaying the video using the startVideo() method provided by the VideoHelper.

val videoHelper = ZoomVideoSDK.getInstance().videoHelper
videoHelper.startVideo()
ZoomVideoSDKVideoHelper videoHelper = ZoomVideoSDK.getInstance().getVideoHelper();
videoHelper.startVideo();

To stop displaying the video of a user, use the stopVideo() method.

videoHelper.stopVideo()
videoHelper.stopVideo();

Render a user's video

The Video SDK allows you to render the video of each user who joins a session. To do so, you'll have to perform the following steps.

  1. Retrieve the ZoomVideoSDKUser object related to each user as they join the session.
  2. Obtain the video canvas from each user.
  3. Create a ZoomVideoSDKVideoView to render each user's video.
  4. Remove the user's video from the view.

Retrieve user information

The ZoomVideoSDKUserHelper helps with retrieval of user information associated with users as they join a session. To access the user information of users as they join the session, respond to the onUserJoin callback.

override fun onUserJoin(userHelper: ZoomVideoSDKUserHelper, userList: MutableList<ZoomVideoSDKUser>) {
    userList.forEach {
        // Access current user's info here
    }
}
@Override
public void onUserJoin(ZoomVideoSDKUserHelper userHelper, List<ZoomVideoSDKUser> userList) {
    for (ZoomVideoSDKUser user : userList) {
        // Access current user's info here
    }
}

If you have not already implemented a listener for the callback events, see Integrate for details.

Create a video view

Now that you have access to each user represented by a ZoomVideoSDKUser object, you must retrieve the ZoomVideoSDKVideoCanvas of each user whose video you would like to render and pass the VideoView into the canvas to subscribe to that user's video.

// Create a new VideoView within your Activity
val videoView = ZoomVideoSDKVideoView(this)
// Retrieve the canvas from a specific user
val canvas = user.videoCanvas
// Create a new VideoView within your Activity
ZoomVideoSDKVideoView videoView = new ZoomVideoSDKVideoView(this);
// Retrieve the canvas from a specific user
ZoomVideoSDKVideoCanvas canvas = user.getVideoCanvas();

After retrieving the instance of ZoomVideoSDKVideoView either programmatically or from your XML, you will need to pass that instance into the subscribe method of the canvas of the user.

canvas.subscribe(videoView, ZoomVideoSDKVideoAspect.ZoomVideoSDKVideoAspect_Original)
canvas.subscribe(videoView, ZoomVideoSDKVideoAspect.ZoomVideoSDKVideoAspect_Original);

Alternatively, you may define a VideoView in your layout XML.

val videoView: ZoomVideoSDKVideoView = findViewById(R.id.video_view)
canvas.subscribe(videoView, ZoomVideoSDKVideoAspect.ZoomVideoSDKVideoAspect_Original)
ZoomVideoSDKVideoView videoView = findViewById(R.id.video_view);
canvas.subscribe(videoView, ZoomVideoSDKVideoAspect.ZoomVideoSDKVideoAspect_Original);
<us.zoom.sdk.ZoomVideoSDKVideoView
    android:id="@+id/video_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

The following options are available for the aspect parameter.

TypeDescription
ZoomVideoSDKVideoAspect_OriginalDisplay video without any modifications.
ZoomVideoSDKVideoAspect_Full_FilledStretches video to fill the canvas.
ZoomVideoSDKVideoAspect_LetterBoxFor video with a 16:9 aspect ratio shown on a 4:3 screen, black bars will be added to the top & bottom to fit the canvas For video with a 4:3 aspect ratio shown on a 16:9 screen, black bars will be added to the left and right to fit the canvas.
ZoomVideoSDKVideoAspect_PanAndScanFor video with a 16:9 aspect ratio shown on a 4:3 screen, the left & right will be cropped to fit the canvas For video with a 4:3 aspect ratio shown on a 16:9 screen, the top & bottom will be cropped to fit the canvas.

Remove video from a canvas

There might be scenarios where you would want to remove a user's video from a VideoView (e.g. if someone leaves a session, a view is being recycled for use with another user, etc.). When such scenario occur, you must unsubscribe from the user's video by calling the unsubscribe method.

videoCanvas.unsubscribe(videoView)
videoCanvas.unsubscribe(videoView);

Use virtual background

Use ZoomVideoSDKVirtualBackgroundHelper to enable virtual backgrounds. First determine whether the device supports it using isSupportVirtualBackground. If the device supports it, use the helper functions to add, get, set, and remove virtual backgrounds.

To add virtual backgrounds:

  1. Use addVirtualBackgroundItem to add a virtual background item.
  2. Use getVirtualBackgroundItemList to get a list of available virtual background items.
  3. Choose a virtual background item from the list and use setVirtualBackgroundItem to set the virtual background.

Use removeVirtualBackgroundItem to remove the virtual background or set the virtual background to None. Use getSelectedVirtualBackgroundItem to get the current selected background.

// Check if virtual background is supported
fun isSupportVirtualBackground(): Boolean
// Add virtual background item
fun addVirtualBackgroundItem(image: Bitmap): ZoomVideoSDKVirtualBackgroundItem
// Remove virtual background item
fun removeVirtualBackgroundItem(imageItem: ZoomVideoSDKVirtualBackgroundItem): Int
// Get virtual background item list
fun getVirtualBackgroundItemList(): List<ZoomVideoSDKVirtualBackgroundItem>
// Set virtual background item
fun setVirtualBackgroundItem(imageItem: ZoomVideoSDKVirtualBackgroundItem): Int
// Get selected virtual background
fun getSelectedVirtualBackgroundItem(): ZoomVideoSDKVirtualBackgroundItem
// Check if virtual background is supported
boolean isSupportVirtualBackground()
// Add virtual background item
ZoomVideoSDKVirtualBackgroundItem addVirtualBackgroundItem(android.graphics.Bitmap image)
// Remove virtual background item
int removeVirtualBackgroundItem(ZoomVideoSDKVirtualBackgroundItem imageItem)
// Get virtual background item list
List<ZoomVideoSDKVirtualBackgroundItem> getVirtualBackgroundItemList()
// Set virtual background item
int setVirtualBackgroundItem(ZoomVideoSDKVirtualBackgroundItem imageItem)
// Get selected virtual background
ZoomVideoSDKVirtualBackgroundItem getSelectedVirtualBackgroundItem()

Video quality preference

When network bandwidth is limited, you can adjust video quality preferences between resolution and frame rate. For example, you can choose to preserve the video sharpness or smoothness. If bandwidth is not a concern, you can receive the best quality video using a high video resolution and maximum frame rate.

Set your video quality preferences with the ZoomVideoSDKVideoPreferenceSetting.

Video preference modes

Choose from the following modes, depending on what you'd like to prioritize.

  • Balance mode. Zoom will do what is best under the current bandwidth situation and make adjustments as needed. You don't need to set any additional parameters for this mode. This mode is suitable for video conference usage. This is the default preference.
  • Smoothness mode. Preserves the frame rate as much as possible. If network bandwidth degrades, Zoom will sacrifice video resolution to preserve the frame rate. This prioritizes a smooth video frame transition.
  • Sharpness mode. Preserves the resolution as much as possible. If network bandwidth degrades, Zoom will sacrifice the frame rate to preserve video resolution. This prioritizes a sharp video image.
  • Custom mode. Allows you to provide the minimum and maximum frame rate. Use this mode if you have an understanding of your network behavior and a clear idea of how to adjust the frame rate to achieve the desired video quality. You can also use this mode to influence bandwidth usage by increasing or decreasing the maximum frame rate setting. Given a resolution, a lower maximum frame rate results in less bandwidth usage. Note that if the bandwidth cannot be sustained by following the minimum and maximum frame rates, the system will drop down to the next lower resolution.

See the reference documentation for details.

Use cases

Video quality preferences are useful when the primary focus is not the image of a person attending the session, but on other video images where smoothness or sharpness is preferred.

Aside from video conferencing, you may want to set video quality preferences for:

  • Transmission of medical X-ray images.
  • Transmission of video captured by endoscopic cameras during a medical operation.
  • Live sporting event broadcasts, such as co-watching or broadcasting a football game.

Callbacks

The following is an example video callback.

Get notified when a user's video status has changed

override fun onUserVideoStatusChanged(videoHelper: ZoomVideoSDKVideoHelper?, userList: MutableList<ZoomVideoSDKUser>) {
    userList.forEach {
        // Check if the current user's video is on
        val videoStatus = it.videoStatus
        videoStatus.isOn
    }
}
@Override
public void onUserVideoStatusChanged(List<ZoomVideoSDKUser> userList) {
    for (ZoomVideoSDKUser user : userList) {
        // Check if the current user's video is on
        ZoomVideoSDKUserInfo userInfo = userHelper.getUserInfo(userId);
    ZoomVideoSDKVideoStatus videoStatus = user.getVideoStatus();
    videoStatus.isOn();
    }
}