enableScreenShare

@RequiresApi(api = 21)
suspend fun enableScreenShare(data: Intent, enableAudio: Boolean = false)

Starts sharing the screen from a MediaProjection consent the app already collected.

A foreground service is started first, as Android 14 and newer require, and torn down again when the share stops; the SDK declares the permission it needs. Because of that handshake this call takes a noticeable moment to return.

Frame rate and bitrate come from the h720p_15fps profile and the capture size follows the display. To choose a different profile, build a track with VideoSDK.createScreenShareVideoTrack and use the other overload.

Events:

Parameters

data

the result Intent from the consent activity, and only from one whose result code was RESULT_OK.

enableAudio

true also captures system audio from the same projection and mixes it into the microphone track, so muting the mic silences both. Defaults to false.

See also

Throws

code 3054 (ERROR_ALREADY_IN_REQUESTED_STATE) if a share is already live or code 3055 (ERROR_OPERATION_IN_PROGRESS) while another enable is still running, both before the consent is used; code 3016 (ERROR_GET_DISPLAY_MEDIA_PERMISSION_DENIED) if data does not grant a projection; code 3066 (ERROR_ACTION_NOT_SUPPORTED_IN_MODE) outside Mode.SEND_AND_RECV; code 3056 (ERROR_OPERATION_ABORTED) if the share was ended from the system UI before it started; or code 3061 (ERROR_SCREENSHARE_PRODUCE_FAILED) if the server would not accept the shared video.


@RequiresApi(api = 21)
suspend fun enableScreenShare(customTrack: CustomStreamTrack? = null)

Starts sharing the screen with a track from VideoSDK.createScreenShareVideoTrack, which carries the user's consent, the encoder profile, whether to publish simulcast layers and whether to capture system audio.

Fires the same events as the other overload.

Parameters

customTrack

the screen-share track; null falls back to the track from the most recent createScreenShareVideoTrack call, with every choice made on it.

See also

Throws

code 3071 (ERROR_INVALID_CUSTOM_TRACK_CONFIG) if customTrack is a camera or microphone track, code 3048 (ERROR_MEDIA_NOT_READY) if there is no screen-share track to use, or any code the other overload throws.