Set the Video Profile
Update time: 2025/06/11 16:45:39
During video calls or interactive live streaming, hosts or co-hosts can share their screens with remote participants or online audience through NERTC SDK in the form of videos, increasing communication efficiency. This function is generally used for group video chat, online conferencing, and online education.
-
In terms of video conferencing, participants can share local files, data, web pages, and PPT displayed on their screen with other participants in a meeting, enabling them to learn about the content and topics discussed more intuitively.
-
In terms of online classes, teachers can display courseware, notes, and teaching materials to remote students using the screen sharing feature, reducing communication costs under the traditional teaching mode and enhancing user experience in the education scenario.
NERTC SDK realizes screen sharing through the SubStream, which means a channel of uplink video stream is specially started for screen sharing. The video stream for the camera is the mainstream, while the video stream for screen sharing is the SubStream. The two video streams work in parallel, and the host displays the uplink camera view and the screen view simultaneously.
Considerations
- Screen sharing by using the SubStream is available in Android, iOS, Windows, and macOS systems with NERTC SDK V3.9.0. If the SubStream-based screen sharing solution is used, make sure that all members in a room do not join the room through the web terminal, and that all Native terminals have been upgraded to V3.9.0 or later. Otherwise, issues such as call exception will occur during communication because of simultaneous sending of the mainstream and SubStream.
- If your app fails to be forcibly upgraded on all clients and only part of clients use V3.9.0 or later in the screen sharing scenario, make sure that only one channel of uplink video is available for a single user during calls to avoid the abovementioned call exception issue. Disable the video stream using enableLocalVideo and then start the screen sharing stream using startScreenCapture if you need to switch from a video stream to a screen sharing stream. A screen sharing stream can also be switched back to a video stream in a similar way.
- Before sharing your screen, ensure that the function has been enabled in your project.
- APIs such as MediaProjection need to be Android API level 21+. See Google MediaProjection API for usage.
- A foreground service needs to be enabled for the screen sharing system of version Android 10 or later, so add a service to
AndroidManifest.xmland set compileSdkVersion to 29. Add a service based on your business needs.
Local screen sharing
Procedure
- Join a room, and enable screen sharing through startScreenCapture.
- Set up the local SubStream video canvas through setupLocalSubStreamVideoCanvas.
- Stop SubStream-based screen sharing through stopScreenCapture.
Sample code
java ////Request a permission for screen sharing first
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void startScreenCapture() {
MediaProjectionManager mediaProjectionManager =
(MediaProjectionManager) getApplication().getSystemService(
Context.MEDIA_PROJECTION_SERVICE);
startActivityForResult(
mediaProjectionManager.createScreenCaptureIntent(), CAPTURE_PERMISSION_REQUEST_CODE);
}
//Enable the screen sharing API in the response to the permission request
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode != CAPTURE_PERMISSION_REQUEST_CODE)
return;
if(resultCode != Activity.RESULT_OK) {
showToast("You denied the screen recording request.");
getUiKitButtons().find("screen_cast", Boolean.class).setState(false);
return;
}
NERtcScreenConfig screenProfile = new NERtcScreenConfig();
screenProfile.videoProfile = mScreenProfile;
screenProfile.contentPrefer = mScreenContent;
screenProfile.frameRate = mScreenFps;
screenProfile.minFramerate = mScreenMinFps;
screenProfile.bitrate = mScreenEncodeBitrate;
screenProfile.minBitrate = mScreenEncodeMinBitrate;
mScreenService.startScreenCapture(screenProfile, data, new MediaProjection.Callback() {
@Override
public void onStop() {
super.onStop();
showToast("Screen recording has stopped.");
}
});
NERtcEx.getInstance().setupLocalSubStreamVideoCanvas(mScreenView);
}
// Stop screen recording
NERtcEx.getInstance().stopScreenCapture();
Video sharing from a remote client
Procedure
-
A remote user joins a room.
-
Set the remote SubStream playback canvas through setupRemoteSubStreamVideoCanvas.
-
Receive callbacks onUserSubStreamVideoStart from other users for starting the SubStream channel.
-
Subscribe to the remote screen sharing SubStream video through subscribeRemoteSubStreamVideo to receive remote SubStream video data.
-
Receive callbacks from other users for disabling the SubStream through onUserSubStreamVideoStop to stop screen sharing.
Sample code
public void onUserSubStreamVideoStart(long uid,int maxProfile) {
Log.i(TAG, "onUserSubStreamVideoStart uid: " + uid);
NERtcEx.getInstance().subscribeRemoteSubStreamVideo(
user.userId, true);
NERtcEx.getInstance().setupRemoteSubStreamVideoCanvas(view, uid);
}





