startScreenCapture method
void
startScreenCapture(
- int? viewId,
- TRTCVideoStreamType streamType,
- TRTCVideoEncParam encParam
override
Start screen sharing
This API can capture the content of the entire screen or a specified application and share it with other users in the same room. (iOS platform calls this interface to support only sharing within the application. System-level sharing requires the use of startScreenCaptureByReplaykit)
Parameters:
- encParam(TRTCVideoEncParam):
- Image encoding parameters used for screen sharing, which can be set to empty, indicating to let the SDK choose the optimal encoding parameters (such as resolution and bitrate).
- streamType(TRTCVideoStreamType):
- Channel used for screen sharing, which can be the primary stream (TRTCVideoStreamType.big) or substream (TRTCVideoStreamType.sub).
- viewId(int):
- Parent control of the rendering control, which can be set to 0, indicating not to display the preview of the shared screen. (Currently only Android can do local preview)
Note:
- A user can publish at most one primary stream (TRTCVideoStreamType.big) and one substream (TRTCVideoStreamType.sub) at the same time.
- By default, screen sharing uses the substream image. If you want to use the primary stream for screen sharing, you need to stop camera capturing (through stopLocalPreview) in advance to avoid conflicts.
- Only one user can use the substream for screen sharing in the same room at any time; that is, only one user is allowed to enable the substream in the same room at any time.
- When there is already a user in the room using the substream for screen sharing, calling this API will return the TRTCCloudListener.onError (ERR_SERVER_CENTER_ANOTHER_USER_PUSH_SUB_VIDEO) callback.
Implementation
@override
void startScreenCapture(int? viewId, TRTCVideoStreamType streamType, TRTCVideoEncParam encParam) async {
TRTCLog(_tag, "startScreenCapture: viewId:$viewId, streamType:$streamType, encParam:$encParam");
if (TRTCPlatform.isIOS) {
TRTCMethodChannel().startScreenCapture(viewId, streamType, encParam);
return;
}
int? effectiveViewId = viewId;
if (effectiveViewId != null && effectiveViewId != 0 && !TRTCCloudVideoView.containsViewId(effectiveViewId)) {
TRTCLog(
_tag,
"startScreenCapture WARNING: viewId=$effectiveViewId is invalid (not registered in TRTCCloudVideoView). "
"Fallback to no local preview. Ensure the TRTCCloudVideoView is created and onViewCreated has fired before calling startScreenCapture.",
level: 3, // warning
);
effectiveViewId = null;
}
TRTCCloudNative.instance.startScreenCapture(_isNativeTexturePlatform ? null : effectiveViewId, streamType, encParam);
if (_isNativeTexturePlatform) {
if (effectiveViewId == null || effectiveViewId == 0) {
await TRTCMethodChannel().unsetLocalTextureRender(streamType);
if (_screenCaptureStreamType == streamType) {
_screenCaptureStreamType = null;
}
} else {
_screenCaptureStreamType = streamType;
await TRTCMethodChannel().setLocalTextureRender(effectiveViewId, streamType);
}
}
}