Custom Screen Share Track - Android
You can pass a custom screen share track when a participant shares their screen. Use it to choose the video encoder config, simulcast and the device's audio for the screen share and send it to other participants.
Creating a Custom Screen Share Track
- You can create a Screen Share track using
createScreenShareVideoTrack()method ofVideoSDK. - This method can be used to create screen share track using different encoding parameters.
Parameters
-
encoderConfig:
- type:
String? - required:
true - default:
h720p_15fps - Allowed values :
h360p_30fps|h480p_15fps|h480p_30fps|h720p_5fps|h720p_15fps|h720p_30fps|h1080p_15fps|h1080p_30fps - The encoder config to use for the screen share track. Pass
nullto use the default.
- type:
note
Above mentioned encoder configurations are valid for both, landscape as well as portrait mode.
-
data
- type:
Intent? - required:
true - The
Intentreceived inonActivityResultwhen the user grants screen share permission. If it isnull(the user declined), the method returnsnull.
- type:
-
multiStream
- type:
Boolean - required:
false - default:
false - If
true, the screen share is published in several quality layers (simulcast) instead of one.
- type:
-
withAudio
- type:
Boolean - required:
false - default:
false - If
true, the device's audio is shared along with the screen. It is mixed into your microphone audio, so muting the mic also mutes it. This needs Android 10 (API 29) or later and theRECORD_AUDIOpermission.
- type:
Returns
CustomStreamTrack?: the track, ornullwhen the user declined orencoderConfigis not one of the allowed values. The second case also reports3071ononError.
Example
// data is received from onActivityResult method.
val track = VideoSDK.createScreenShareVideoTrack("h720p_5fps", data)
if (track != null) {
lifecycleScope.launch {
try {
meeting.enableScreenShare(track)
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "Screen share failed: ${e.code} ${e.name}")
}
}
}
Using Custom Screen Share Track
Custom Track with enableScreenShare()
In order to switch tracks during the meeting, you have to pass the CustomStreamTrack in the enableScreenShare() method of Meeting. It is a suspend function, so call it from a coroutine.
note
enableScreenShare() throws VideoSDKException with code 3054 while the screen is already being shared. Call disableScreenShare() before you share with a new track.
private fun askPermissionForScreenShare() {
val mediaProjectionManager = application.getSystemService(
Context.MEDIA_PROJECTION_SERVICE
) as MediaProjectionManager
startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE
)
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode != CAPTURE_PERMISSION_REQUEST_CODE) return
if (resultCode == RESULT_OK) {
val track = VideoSDK.createScreenShareVideoTrack("h720p_5fps", data) ?: return
lifecycleScope.launch {
try {
meeting.enableScreenShare(track)
} catch (e: VideoSDKException) {
Log.e("VideoSDK", "Screen share failed: ${e.code} ${e.name}")
}
}
}
}
Got a Question? Ask us on discord

