Handle multiple screen shares

By default, only one participant can share at a time. The session host can enable simultaneous sharing so that several participants share at once, or lock sharing so that only the host can share. On the viewer side, you then choose which share to render by walking the share-action list on a user.

Host: enable multi-share

The host controls whether participants can share simultaneously with enableMultiShare. Toggle it on before participants try to share. Calls to start a share while another share is in progress will fail when multi-share is off.

val shareHelper = ZoomVideoSDK.getInstance().shareHelper
// Host: allow multiple users to share at the same time.
shareHelper.enableMultiShare(true)
// Anyone: check whether multi-share is currently allowed.
val multiShare = shareHelper.isMultiShareEnabled
ZoomVideoSDKShareHelper shareHelper = ZoomVideoSDK.getInstance().getShareHelper();
// Host: allow multiple users to share at the same time.
shareHelper.enableMultiShare(true);
// Anyone: check whether multi-share is currently allowed.
boolean multiShare = shareHelper.isMultiShareEnabled();

Host: lock sharing

The session host can prevent other participants from starting a share with lockShare. While share is locked, only the host can initiate a share. Check isShareLocked to drive the UI for non-host users.

val shareHelper = ZoomVideoSDK.getInstance().shareHelper
// Host: lock screen sharing for everyone else.
shareHelper.lockShare(true)
// Anyone: check the current state.
val locked = shareHelper.isShareLocked
ZoomVideoSDKShareHelper shareHelper = ZoomVideoSDK.getInstance().getShareHelper();
// Host: lock screen sharing for everyone else.
shareHelper.lockShare(true);
// Anyone: check the current state.
boolean locked = shareHelper.isShareLocked();

Viewer: subscribe to a specific share

onUserShareStatusChanged is the easiest way to render the latest share, but if you need to render a specific user's share (for example, to build a UI where the viewer can switch between two presenters), get that user's share-action list and subscribe to the entry you want.

This pattern is for rendering remote users' shares. To confirm your own share started, check the return value of startShareScreen. Don't try to subscribe to your own share canvas.

Add a container to your layout where the share view will live.

<FrameLayout
    android:id="@+id/share_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

Then attach a ZoomVideoSDKVideoView to that container and subscribe it to the chosen share canvas:

// The remote user whose share you want to render.
val user: ZoomVideoSDKUser = /* ... */
val shareActions = user.shareActionList
if (shareActions.isNotEmpty()) {
    // A user can have multiple share actions if they share more than one source.
    val shareAction: ZoomVideoSDKShareAction = shareActions[0]
    val container = findViewById<FrameLayout>(R.id.share_container)
    val videoView = ZoomVideoSDKVideoView(this)
    container.addView(videoView)
    shareAction.shareCanvas.subscribe(
        videoView,
        ZoomVideoSDKVideoAspect.ZoomVideoSDKVideoAspect_Original,
        ZoomVideoSDKVideoResolution.ZoomVideoSDKResolution_Auto
    )
}
// The remote user whose share you want to render.
ZoomVideoSDKUser user = /* ... */;
List<ZoomVideoSDKShareAction> shareActions = user.getShareActionList();
if (!shareActions.isEmpty()) {
    // A user can have multiple share actions if they share more than one source.
    ZoomVideoSDKShareAction shareAction = shareActions.get(0);
    FrameLayout container = findViewById(R.id.share_container);
    ZoomVideoSDKVideoView videoView = new ZoomVideoSDKVideoView(this);
    container.addView(videoView);
    shareAction.getShareCanvas().subscribe(
        videoView,
        ZoomVideoSDKVideoAspect.ZoomVideoSDKVideoAspect_Original,
        ZoomVideoSDKVideoResolution.ZoomVideoSDKResolution_Auto
    );
}

When the share stops or your Activity is destroyed, call unSubscribe on the canvas and remove the view from the container. For the lifecycle pattern, see Unsubscribe when your view goes away.