Screen sharing

Updated

Implement key workflow steps required to develop a fully functional video calling app

During Video Calling sessions, hosts use the screen sharing feature in the Agora Video SDK to share their screen content with other users or viewers in the form of a video stream. Screen sharing is typically used in the following use-cases:

Use-caseDescription
Online educationTeachers share their slides, software, or other teaching materials with students for classroom demonstrations.
Game live broadcastHosts share their game footage with the audience.
Interactive live broadcastAnchors share their screens and interact with the audience.
Video conferencingMeeting participants share the screen to show a presentation or documents.
Remote controlA controlled terminal displays its desktop on the master terminal.

Agora screen sharing offers the following advantages:

  • Ultra HD quality experience: Supports Ultra HD video (4K resolution, 60 FPS frame rate), giving users a smoother, high-definition, ultimate picture experience.
  • Multi-app support: Compatible with many mainstream apps such as WPS Office, Microsoft Office Power Point, Visual Studio Code, Adobe Photoshop, Windows Media Player, and Scratch. This makes it convenient for users to directly share specific apps.
  • Multi-device support: Supports multiple devices sharing at the same time. Screen sharing is compatible with Windows 8 systems, devices without independent graphics cards, dual graphics card devices, and external screen devices.
  • Multi-platform adaptation: Supports iOS, Android, macOS, Windows, Web, Unity, Flutter, React Native, Unreal Engine, and other platforms.
  • High security: Supports sharing only a single app or part of the screen. Also supports blocking specified app windows, effectively ensuring user information security.

This page shows you how to implement screen sharing in your game.

Understand the tech

The screen sharing feature provides the following screen sharing modes for use in various use-cases:

Screen sharing use-cases

  • Share the entire screen: Share your entire screen, including all the information on the screen. This feature supports collecting and sharing information from two screens at the same time.
  • Share an app window: If you don't want to share the entire screen with other users, you can share only the area within an app window.
  • Share a designated screen area: If you only want to share a portion of the screen or app window, you can set a sharing area when starting screen sharing.

Screen sharing modes are available on different platforms as follows:

  • Desktop (Windows and macOS): Supports all screen sharing features listed above.

  • Mobile (Android and iOS): Only supports sharing the entire screen.

Prerequisites

  • Ensure that you have implemented the SDK quickstart in your project.

Set up your project

You use the iOS native ReplayKit framework in the extension to record the screen, and then add the screen sharing stream to the channel as a user. Since Apple does not support capturing the screen in the main process of the app, you create a separate extension for the screen sharing stream.

Implement screen sharing

This section introduces how to implement screen sharing in your project.

When enabling screen sharing on Android, call the StartScreenCapture method. Depending on the actual business use-case, choose either of the following methods to implement screen sharing:

  • Call StartScreenCapture before joining the channel, then call JoinChannel[2/2] to join the channel and set publishScreenCaptureVideo to true to start screen sharing.

    // Call StartScreenCapture to enable screen sharing before joining a channel.
    ScreenCaptureParameters2 screenCaptureParameters2 = new ScreenCaptureParameters2();
    screenCaptureParameters2.captureVideo = true;
    screenCaptureParameters2.captureAudio = true;
    RtcEngine.StartScreenCapture(screenCaptureParameters2);
    // Call JoinChannel to join a channel.
    ChannelMediaOptions channelMediaOptions = new ChannelMediaOptions();
    channelMediaOptions.publishScreenCaptureVideo.SetValue(true);
    channelMediaOptions.publishScreenCaptureAudio.SetValue(true);
    channelMediaOptions.publishCameraTrack.SetValue(false);
    channelMediaOptions.publishMicrophoneTrack.SetValue(false);
    RtcEngine.JoinChannel("token", "channelId", uid, channelMediaOptions);
  • Call StartScreenCapture after joining the channel, then call UpdateChannelMediaOptions to set publishScreenCaptureVideo to true to start screen sharing.

    // Call JoinChannel to join the channel.
    RtcEngine.JoinChannel(_token, _channelName);
    ScreenCaptureParameters2 screenCaptureParameters2 = new ScreenCaptureParameters2();
    screenCaptureParameters2.captureVideo = true;
    screenCaptureParameters2.captureAudio = true;
    // Enable screen sharing.
    RtcEngine.StartScreenCapture(screenCaptureParameters2);
    ChannelMediaOptions channelMediaOptions = new ChannelMediaOptions();
    channelMediaOptions.publishScreenCaptureVideo.SetValue(true);
    channelMediaOptions.publishScreenCaptureAudio.SetValue(true);
    channelMediaOptions.publishCameraTrack.SetValue(false);
    channelMediaOptions.publishMicrophoneTrack.SetValue(false);
    // Update channel media options.
    RtcEngine.UpdateChannelMediaOptions(channelMediaOptions);

Limitations

Be aware of the following limitations:

  • The video unit price for a screen-sharing stream is based on the video resolution you set in ScreenCaptureParameters. If you do not pass dimensions in ScreenCaptureParameters, Agora bills you at the default resolution of 1920 x 1080 (2,073,600). See Pricing for details.
  • Due to system limitations, screen sharing is only supported on iOS 12.0 and above.
  • This feature requires a high level of device performance. Agora recommends that you use an iPhone X or above.

Reference

This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

Sample project

Agora provides an open-source Unity sample project on GitHub. Download and explore this project for a more detailed example.

API reference