All Products
Search
Document Center

:Update of Push SDK for Android

Last Updated:Mar 22, 2024

This topic describes how to update Push SDK for Android from V4.0.2 to V4.1.0 or later.

Prerequisites

The latest version of Push SDK for Android is downloaded.

For more information, see Download SDKs.

Procedure

Remove the related class libraries and resource files of SDK V4.0.2 from the project. Add the related class libraries and resource files of SDK V4.1.0 or later. Check and modify the related key methods and methods in the main process of stream ingest.

  1. In the libs directory of the project, replace the AliLiveSdk.aar file with the AlivcLivePusher.aar file in the SDK package of V4.1.0 or later.

  2. In the build.gradle file, update ApsaraVideo Player SDK to the latest version.

    Note

    For more information about the release notes of ApsaraVideo Player SDK for Android, see Release notes for ApsaraVideo Player SDK for Android.

    The following code shows an example on how to modify the configurations of ApsaraVideo Player SDK for Android. In this example, the SDK version is released on August 2021.

    implementation 'com.aliyun.sdk.android:AliyunPlayer:5.4.2.0-full'
    implementation 'com.aliyun.sdk.android:AlivcArtc:5.4.2.0'
  3. If you want to implement the smart retouching feature in your application, add the beauty, beautyui, imageutil, and queenbeauty model files in the demo directory to facilitate the integration of Queen SDK for Android and UI.

  4. Changes are made to some key methods. View the "Comparison of key methods" section of this topic to check and modify the related methods in your code.

  5. Changes are made to some methods in the main process of stream ingest. View the "Changes in methods in the main process of stream ingest" section of this topic to check and modify your code.

Comparison of key methods

  • Basic methods

    V4.0.2

    V4.1.0 and later

    Description

    getSdkVersion

    getSdkVersion

    Queries the version number of Push SDK for Android.

    create

    init

    Creates a stream ingest object.

    destroy

    destroy

    Destroys a stream ingest object.

    setStatusCallback

    setLivePushInfoListener

    Sets the callback for the stream ingest status.

    setNetworkCallback

    setLivePushNetworkListener

    Sets the callback for the network status during stream ingest.

    setLogDirPath

    setLogDirPath

    Sets the path for storing the log files of Push SDK for Android.

    To prevent log loss, you must call this method before other methods. In addition, make sure that the specified path exists and is writable.

    setLogLevel

    setLogLevel

    Sets the log level.

  • Basic stream ingest methods

    V4.0.2

    V4.1.0 and later

    Description

    startPreview

    startPreview

    Starts the preview. This method is called on the streamer side.

    stopPreview

    stopPreview

    Stops the preview. This method is called on the streamer side.

    pausePush

    pause

    Stops the camera from collecting live streams and ingests standby streams. This method is supported only for stream ingest over Real-Time Messaging Protocol (RTMP). You must call the startPush method before the pausePush method.

    resumePush

    resume()

    Enables the camera to collect live streams again and stops ingesting standby streams. This method is supported only for stream ingest over RTMP. You must call the pausePush method before the resumePush method.

    startPush

    startPush

    Starts the stream ingest.

    stopPush

    stopPush

    Stops the stream ingest.

    isPublishing

    isPublishing

    Queries whether streams are being ingested.

    getPublishUrl

    getPushUrl

    Queries the current ingest URL.

  • Video-related methods

    V4.0.2

    V4.1.0 and later

    Description

    setPreviewMode

    setPreviewMode

    Sets the preview mode.

    isAudioOnly

    isAudioOnly

    Queries whether the ingested streams are audio-only streams.

    switchCamera

    switchCamera

    Switches between the front and rear cameras.

    setCameraZoom

    setCameraZoom

    Sets the zoom factor of the camera and specifies whether to enable the flash.

    isCameraExposurePointSupported

    setExposureCompensation

    Queries whether an exposure point can be set for the camera.

    setCameraFocusPoint

    setLiveCameraFocus

    Sets the focus point of the camera.

  • Audio-related methods

    V4.0.2

    V4.1.0 and later

    Description

    setMute

    setMute

    Specifies whether the frames collected from the local audio are mute frames.

    isAudioOnly

    isAudioOnly

    Queries whether the ingested streams are audio-only streams.

    enableEarBack

    setBGMEarsBack

    Enables in-ear monitoring. To prevent echoes, we recommend that you enable in-ear monitoring after you insert the headset.

    playBGM

    startBGMAsync

    Starts the playback of background music.

    stopBGM

    stopBGM

    Stops the playback of background music.

    pauseBGM

    pauseBGM

    Pauses the playback of background music.

    resumeBGM

    resumeBGM

    Resumes the playback of background music.

    setBGMVolume

    setBGMVolume

    Sets the volume of background music.

Changes in methods in the main process of stream ingest

  1. Create an engine.

    V4.0.2: AliLiveEngine

    V4.1.0 and later: AlivcLivePusher

    // Create an AliLiveRTMPConfig object.
    AliLiveRTMPConfig rtmpConfig = new AliLiveRTMPConfig();
    // Initialize the bitrate settings.
    rtmpConfig.videoInitBitrate = 1000;
    rtmpConfig.videoTargetBitrate = 1500;
    rtmpConfig.videoMinBitrate = 600;
    // Create an AliLiveConfig object.
    AliLiveConfig mAliLiveConfig = new AliLiveConfig(rtmpConfig);
    // Initialize the resolution and frame rate, specify whether to enable high-definition preview, and specify the default image to be displayed after a pause.
    mAliLiveConfig.videoFPS = 20;
    mAliLiveConfig.videoPushProfile = AliLiveConstants.AliLiveVideoPushProfile.AliLiveVideoProfile_540P;
    mAliLiveConfig.enableHighDefPreview = false;
    mAliLiveConfig.pauseImage = bitmap;
    mAliLiveConfig.accountId = "";
    AliLiveEngine mAliLiveEngine = AliLiveEngine.create(PushActivity.this, mAliLiveConfig);
    // Initialize the stream ingest configurations.
    AlivcLivePushConfig mAlivcLivePushConfig = new AlivcLivePushConfig();
    // Initialize the resolution. The default resolution is 540p. The supported maximum resolution is 720p.
    mAlivcLivePushConfig.setResolution(AlivcResolutionEnum.RESOLUTION_540P);
    // Initialize the frame rate. We recommend that you set the frame rate to 20 frames per seconds (FPS).
    mAlivcLivePushConfig.setFps(AlivcFpsEnum.FPS_20); 
    // Enable adaptive bitrate streaming. Default value: true.
    mAlivcLivePushConfig.setEnableBitrateControl(true); 
    // By default, the preview is in portrait mode. You can change the mode to landscape left or landscape right. 
    mAlivcLivePushConfig.setPreviewOrientation(AlivcPreviewOrientationEnum.ORIENTATION_PORTRAIT); 
    // Specify the audio encoding format.
    mAlivcLivePushConfig.setAudioProfile(AlivcAudioAACProfileEnum.AlivcAudioAACProfileEnum.AAC_LC);
    AlivcLivePusher mAlivcLivePusher = new AlivcLivePusher();mAlivcLivePusher.init(mContext, mAlivcLivePushConfig);
  2. Create a preview.

    Important

    The methods used to start and end a preview must be used in pairs. For example, use startPreview and stopPreview in pairs or use startPreviewAysnc and stopPreviewAysnc in pairs.

    V4.0.2

    V4.1.0 and later

    // Create a preview view.
    AliLiveRenderView mAliLiveRenderView = mAliLiveEngine.createRenderView(false);
    // Add the preview view to the layout.
    addSubView(mAliLiveRenderView);
    // Specify the preview mode.
    mAliLiveEngine.setPreviewMode(AliLiveRenderModeAuto, AliLiveRenderMirrorModeOnlyFront);
    // Enable preview.
    mAliLiveEngine.startPreview(mAliLiveRenderView);

    You can start the preview after you initialize the livePusher object. Use the mSurfaceView parameter for camera previews. The following code provides an example:

    // Enable preview. You can also call the startPreviewAysnc asynchronous method based on your business requirements.
    mAlivcLivePusher.startPreview(mSurfaceView)
  3. Start the stream ingest.

    V4.0.2

    V4.1.0 and later

    mAliLiveEngine.startPush(mPushUrl);
    mAlivcLivePusher.startPush(mPushUrl);
  4. Stop the stream ingest.

    V4.0.2

    V4.1.0 and later

    // Stop the preview.
    mAliLiveEngine.stopPreview();
    // Stop the stream ingest.
    mAliLiveEngine.stopPush();
    // Destroy the AliLiveEngine object.
    mAliLiveEngine.destroy();
    mAliLiveEngine = null;
    // Stop the preview.
    mAliLivePusher.stopPreview();
    // Stop the stream ingest.
    mAliLivePusher.stopPush();
    // Destroy the AliLivePusher object.
    mAliLivePusher.destroy();
    mAliLivePusher = null;