tencent cloud


Publishing from Screen

Last updated: 2024-01-13 15:49:41


    Publishing from the camera refers to the process of collecting video and audio data from the mobile phone's camera and mic, encoding the data, and pushing it to cloud-based live streaming platforms. Tencent Cloud live_flutter_plugin provides the camera push capabilities via V2TXLivePusher APIs.

    Sample Code

    Tencent Cloud offers an easy-to-understand API example project to help you quickly learn how to use different APIs.
    GitHub Address

    Environment Requirements


    Screen recording is supported in Android 5.0 and above.
    Floating windows need to be enabled manually on some mobile phones and systems.


    Screen recording is a new feature in iOS 10. In addition to using ReplayKit to record video from the screen, which is possible in iOS 9, with iOS 10, users can also stream live video from the screen. For details, see Go Live with ReplayKit. In iOS 11, Apple made ReplayKit more usable and more universally applicable and launched ReplayKit2, going from supporting ReplayKit alone to allowing the recording of the entire screen. Therefore, we recommend using ReplayKit2 in iOS 11 to enable the screen sharing feature. Screen sharing relies on extensions, which operate as independent processes. However, to ensure system smoothness, iOS allocates limited resources to extensions and may kill extensions with high memory usage. Given this, Tencent Cloud has further reduced the memory usage of LiteAVSDK while retaining its high streaming quality and low latency to ensure the stability of extensions.
    This document describes how to use ReplayKit 2 on iOS 11 to push streams from the screen. The parts about the use of the SDK also apply to other custom stream push scenarios. For more information, see the code sample in the Live Demo Screen folder of the demo.
    1. Create the live streaming extension Open your project with Xcode and select New > Target... > Broadcast Upload Extension, as shown below.
    Enter a product name and click Finish. A new directory with the product name entered will appear in your project. Under the directory, there is an automatically generated SampleHandler class, which is responsible for screen recording operations.
    Xcode 9 or later is required, and your iPhone must be updated to iOS 11 or later. Screen recording is not supported on emulators.
    2. Import TXLiteAVSDK_ReplayKitExt.framework Import TXLiteAVSDK_ReplayKitExt.framework into the live streaming extension the same way you import a framework into the host application. The system libraries the SDK depends on are also the same. For more information, see iOS.

    Getting Started

    1. Set dependencies

    Integrate live_flutter_plugin into your application as instructed in SDK Integration Guide.
    live_flutter_plugin: latest version number

    2. Configure a license for the SDK

    1. Get the license:
    If you have the required license, get the license URL and key in the CSS console.
    If you don't have the required license, apply for a license as instructed in New License and Renewal.
    2. Before your application calls features of live_flutter_plugin, complete the following configuration:
    import 'package:live_flutter_plugin/v2_tx_live_premier.dart';
    /// Tencent Cloud license management page (https://console.tencentcloud.com/live/license)
    setupLicense() {
    // The license URL of the current application
    var LICENSEURL = "";
    // The license key of the current application
    var LICENSEURLKEY = "";
    V2TXLivePremier.setLicence(LICENSEURL, LICENSEURLKEY);
    The packageName/BundleId configured in the license must be the same as that of the application; otherwise, stream push will fail.

    3. Create a pusher object

    Create a V2TXLivePusher object, which will be responsible for publishing operations.
    V2TXLivePusher livePusher = V2TXLivePusher(V2TXLiveMode.v2TXLiveModeRTMP);

    4. Start stream push

    After completing Step 1, you can use the code below to start publishing streams:
    String rtmpUrl = "rtmp://2157.livepush.myqcloud.com/live/xxxxxx";
    How can I obtain a valid publishing URL? Activate CSS. In the CSS console, go to Auxiliary Tools > Address Generator to generate a stream push URL. For more information, see Publishing/Playback URL.
    Why is V2TXLIVE_ERROR_INVALID_LICENSE returned?If the startPush API returns V2TXLIVE_ERROR_INVALID_LICENSE, it means your license verification failed. Please check your configuration against Step 2. Configure a license for the SDK.

    5. Stop stream push

    As there can be only one V2TXLivePusher object running at a time, make sure that you release all the resources when stopping publishing.
    // Stop screen sharing and release the resources
    void stopPush() {

    Event Handling

    Listening for events

    The SDK listens on push events and errors via the V2TXLivePusherObserver delegate. See v2_tx_live_code library for a detailed list of events and error codes.


    An error indicates that the SDK encountered a serious problem that made it impossible for stream publishing to continue.
    Event ID
    A common unclassified error occurred.
    An invalid parameter was passed in during API calling.
    The API call was rejected.
    The API cannot be called.
    Failed to call the API due to invalid license.
    The server request timed out.
    The server could not handle your request.


    A warning indicates that the SDK encountered a problem whose severity level is warning. Warning events trigger tentative protection or recovery logic and can often be resolved.
    Event ID
    Bad network connection: data upload blocked due to limited upstream bandwidth.
    Stuttering during video playback.
    Failed to turn the camera on.
    The camera is occupied. Try a different camera.
    No access to the camera. This usually occurs on mobile devices and may be because the user denied the access.
    Failed to turn the mic on.
    The mic is occupied. This occurs when, for example, the user is having a call on the mobile device.
    No access to the mic. This usually occurs on mobile devices and may be because the user denied the access.
    The system does not support screen sharing.
    Failed to start screen recording. If this occurs on a mobile device, it may be because the user denied the access.
    Screen recording was stopped by the system.


    ReplayKit2 is a new framework introduced by Apple in iOS 11, for which relatively few official documents have been released. The framework is still being improved, and problems have been found. See below for some common questions you may have when using ReplayKit2.
    1. When does screen recording stop automatically? Screen recording stops automatically when the screen locks or there is an incoming call. At such times, the broadcastFinished function in SampleHandler will be invoked, and you can send a notification to users about the interruption.
    2. Why does screen recording stop sometimes during screen sharing? The problem usually occurs after landscape/portrait mode switch if the resolution for stream publishing is set high. The broadcast upload extension is allocated a memory of only 50 MB and will be killed if its memory usage exceeds the limit. Given this, we recommend that you set the resolution to 720p or lower.
    3. Why are images streamed from the screen of iPhone X distorted? iPhone X has a notch at the top of the screen, so video captured from the screen is not in the aspect ratio of 16:9. If you set the output resolution for stream publishing to 16:9, for example, to HD (960 × 540), the images published will be slightly distorted because their original aspect ratio is not 16:9. We recommend that you set the resolution according to your screen size. Besides, if you play video streamed from the screen of iPhone X in aspect fit mode, the video may have black bars, and if you play it in aspect fill mode, the video may be cropped.
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support