Custom ScreenShare Sources - Android
To deliver high-quality livestreams, it's essential to fine-tune screen share tracks being broadcasted. Whether youโre hosting a webinar, or going live with a presentation, using custom media tracks gives you better control over stream quality and performance.
Custom Screen Share Trackโ
This feature enables the customization of screenshare streams with enhanced optimization modes and predefined encoder configuration (resolution + FPS) for specific use cases, which can then be sent to other hosts and audience members.
How to Create Custom Screen Share Track ?
โ
- You can create a Screen Share track using
createScreenShareVideoTrack()
method ofVideoSDK
. - This method can be used to create video track using different encoding parameters and optimization mode.
Exampleโ
- Kotlin
- Java
// data is received from onActivityResult method.
VideoSDK.createScreenShareVideoTrack(
// This will accept the height & FPS of video you want to capture.
"h720p_15fps", // `h360p_30fps` | `h1080p_30fps` // Default : `h720p_15fps`
// It is Intent received from onActivityResult when user provide permission for ScreenShare.
data,
// Pass Conext
this)
//Callback to this listener will be made when track is ready with CustomTrack as parameter
{
track ->
meeting!!.enableScreenShare(track)
}
// data is received from onActivityResult method.
VideoSDK.createScreenShareVideoTrack(
// This will accept the height & FPS of video you want to capture.
"h720p_15fps", // `h360p_30fps` | `h1080p_30fps` // Default : `h720p_15fps`
/highlight-next-line
// It is Intent received from onActivityResult when user provide permission for ScreenShare
data,
// Pass Conext
this,
//Callback to this listener will be made when track is ready with CustomTrack as parameter
(track)->{meeting.enableScreenShare(track);}
);
How to Setup Custom Screen Share Track ?
โ
In order to switch tracks during the meeting, you have to pass the CustomStreamTrack
in the enableScreenShare()
method of Meeting
.
Make sure to call disableScreenShare()
before you create a new track as it may lead to unexpected behavior.
Exampleโ
- Kotlin
- Java
@TargetApi(21)
private fun askPermissionForScreenShare() {
val mediaProjectionManager = application.getSystemService<Any>(
Context.MEDIA_PROJECTION_SERVICE
) as MediaProjectionManager
startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE
)
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
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) {
VideoSDK.createScreenShareVideoTrack("h720p_15fps", data, this) { track ->
liveStream!!.enableScreenShare(track)
}
}
}
@TargetApi(21)
private void askPermissionForScreenShare() {
MediaProjectionManager mediaProjectionManager =
(MediaProjectionManager) getApplication().getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode != CAPTURE_PERMISSION_REQUEST_CODE)
return;
if (resultCode == Activity.RESULT_OK) {
VideoSDK.createScreenShareVideoTrack("h720p_15fps", data, this, (track)->{
liveStream.enableScreenShare(track);
});
}
}
API Referenceโ
The API references for all the methods and events utilised in this guide are provided below.
Got a Question? Ask us on discord