TRTC supports screen sharing on Android. This means a user can share the screen content of the local system with other users in the same room through the TRTC SDK. Pay attention to the following points regarding this feature:
iOS | Android | macOS | Windows | Electron | Chrome |
---|---|---|---|---|---|
✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
To start screen sharing on Android, simply call the startScreenCapture() API in TRTCCloud
. However, to ensure the stability and video quality of screen sharing, you need to do the following:
Copy the activity below and paste it in the manifest file. You can skip this if the activity is already included in your project code.
<activity
android:name="com.tencent.rtmp.video.TXScreenCapture$TXScreenCaptureAssistantActivity"
android:theme="@android:style/Theme.Translucent"/>
By setting the first parameter encParams
in startScreenCapture(), you can specify the encoding quality of screen sharing. If encParams
is set to null
, the SDK will use the encoding parameters set previously. We recommend the following settings:
Item | Parameter | Recommended Value for Regular Scenarios | Recommended Value for Text-based Teaching |
---|---|---|---|
Resolution | videoResolution | 1280 × 720 | 1920 × 1080 |
Frame rate | videoFps | 10 fps | 8 fps |
Highest bitrate | videoBitrate | 1600 Kbps | 2000 Kbps |
Resolution adaption | enableAdjustRes | NO | NO |
videoBitrate
) refers to the highest output bitrate when a shared screen changes dramatically. If the shared content does not change a lot, the actual encoding bitrate will be lower.Since Android 7.0, apps running in the background tend to be killed by the system if they consume CPU. To prevent your app from being killed when it is sharing the screen in the background, you need to create a floating window when screen sharing starts, which also serves the purpose of reminding the user to avoid displaying personal information as his or her screen is being shared.
public void showView(View view, int width, int height) {
mWindowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
// `TYPE_TOAST` applies only to Android 4.4 and above. On earlier versions, use `TYPE_SYSTEM_ALERT` (the permission needs to be declared in `manifest`).
// Android 7.1 and above set restrictions on `TYPE_TOAST`.
int type = WindowManager.LayoutParams.TYPE_TOAST;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N) {
type = WindowManager.LayoutParams.TYPE_PHONE;
}
mLayoutParams = new WindowManager.LayoutParams(type);
mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
mLayoutParams.flags |= WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
mLayoutParams.width = width;
mLayoutParams.height = height;
mLayoutParams.format = PixelFormat.TRANSLUCENT;
mWindowManager.addView(view, mLayoutParams);
}
Watch screens shared by macOS/Windows users
When a macOS/Windows user in a room starts screen sharing, the screen will be shared through a substream, and other users in the room will be notified through onUserSubStreamAvailable in TRTCCloudDelegate
.
Users who want to watch the shared screen can start rendering the substream image of the remote user by calling the startRemoteSubStreamView API.
Watch screens shared by Android/iOS users
When an Android/iOS user starts screen sharing, the screen will be shared through the primary stream, and other users in the room will be notified through onUserVideoAvailable in TRTCCloudListener
.
Users who want to watch the shared screen can start rendering the primary stream of the remote user by calling the startRemoteView API.
//Sample code: watch the shared screen
@Override
public void onUserSubStreamAvailable(String userId, boolean available) {
startRemoteSubStreamView(userId);
}
Can there be multiple channels of screen sharing streams in a room at the same time?
Currently, each TRTC room can have only one channel of screen sharing stream.
Was this page helpful?