Android

更新时间:
复制 MD 格式

This topic describes how to use the screen sharing feature.

Notes

1. To ensure application security, the screen sharing feature is disabled by default on mobile clients. To enable this feature, submit a ticket.

2. The RTC Android 3.0 software development kit (SDK) already handles requests for screen sharing permissions. Do not request this permission again in your service code. Otherwise, multiple permission confirmation requests for screen sharing may be displayed.

Publisher

Start screen sharing.

// Configure screen sharing stream ingest
// Get the DingRtcEngine instance
DingRtcEngine mRtcEngine = DingRtcEngine.create(getApplicationContext(),"");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
  startForegroundService(sharingService);
}
ret = mRtcEngine.startScreenShare();
.....
  1. After starting stream ingest, use a callback to check whether the screen sharing stream is published.

    public void onScreenSharePublishStateChanged(DingRtcEngine.DingRtcPublishState oldState ,
                                                 DingRtcEngine.DingRtcPublishState newState,
                                                 int elapseSinceLastState, String channel);

    Parameter

    Type

    Description

    oldState

    DingRtcPublishState

    The previous stream ingest state.

    newState

    DingRtcPublishState

    The current stream ingest state.

    elapseSinceLastState

    int

    The time elapsed since the last state change. Unit: ms.

    channel

    String

    The current channel ID.

  2. Stop screen sharing.

    int ret = mRtcEngine.stopScreenShare();
  3. After stopping screen sharing, use a callback to confirm that the stream is unpublished.

    public void onScreenSharePublishStateChanged(DingRtcEngine.DingRtcPublishState oldState ,
                                                 DingRtcEngine.DingRtcPublishState newState,
                                                 int elapseSinceLastState, String channel);

    Parameter

    Type

    Description

    oldState

    AliRtcPublishState

    The previous stream ingest state.

    newState

    AliRtcPublishState

    The current stream ingest state.

    elapseSinceLastState

    int

    The time elapsed since the last state change. Unit: ms.

    channel

    String

    The current channel ID.

Subscriber

Subscribers can subscribe to the screen sharing video stream from the publisher automatically or manually, and set a corresponding View to display the stream. For more information, see DingRtcEngine interface.