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 the Push SDK is downloaded.
For information about the new versions of Push SDK, see SDK download and release notes.
Procedure
Remove the class libraries and resource files of Push SDK V4.0.2 from your project.
Then, add the class libraries and resource files of Push SDK V4.1.0 or later to your project.
- In the libs directory, use the AlivcLivePusher.aar file of Push SDK V4.1.0 or later to replace the AliLiveSdk.aar file of Push SDK V4.0.2.
- Update ApsaraVideo Player SDK to the latest version in the build.gradle file.
Take the 2021-08 release of the ApsaraVideo Player SDK for Android for example. Update
the file with the following information:
implementation 'com.aliyun.sdk.android:AliyunPlayer:5.4.2.0-full'
implementation 'com.aliyun.sdk.android:AlivcArtc:5.4.2.0'
- If you want to implement the smart retouching feature in your app, add the beauty,
beautyui, imageutil, and queenbeauty model files in the demo to facilitate the integration
of the Queen SDK and UI.
- Modify specific methods, as described in the Key methods section of this topic.
- Modify specific methods for the major process, as described in the Changes in the methods for major process section of this topic.
Key methods
- Basic methods
V4.0.2 |
V4.1.0 and later
|
Description |
getSdkVersion |
getSdkVersion |
Queries the version of Push SDK. |
create |
init |
Creates a stream ingest object. |
destroy |
destory |
Destroys the 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.
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 RTMP. You must call the startPush method
before the pausePush method to prevent an invalid call order.
|
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 to prevent an invalid call order.
|
startPush |
startPush |
Starts to ingest streams. |
stopPush |
stopPush |
Stops ingesting streams. |
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 the 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 |
Plays background music. |
stopBGM |
stopBGM |
Stops playing 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 the methods for major process
- Create an engine.
AliLiveEngine in V4.0.2 |
AlivcLivePusher in V4.1.0 and later
|
// 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. The default value is 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);
// Set the audio encoding format.
mAlivcLivePushConfig.setAudioProfile(AlivcAudioAACProfileEnum.AlivcAudioAACProfileEnum.AAC_LC);
AlivcLivePusher mAlivcLivePusher = new AlivcLivePusher();mAlivcLivePusher.init(mContext, mAlivcLivePushConfig);
|
- Create a preview.
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);
// Set the preview mode.
mAliLiveEngine.setPreviewMode(AliLiveRenderModeAuto, AliLiveRenderMirrorModeOnlyFront);
// Start the 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:// Start the preview. You can also call the asynchronous method startPreviewAysnc based on your needs to start the preview.
mAlivcLivePusher.startPreview(mSurfaceView)
|
- Start to ingest streams.
V4.0.2 |
V4.1.0 and later
|
mAliLiveEngine.startPush(mPushUrl);
|
mAlivcLivePusher.startPush(mPushUrl);
|
- Stop ingesting streams.
V4.0.2 |
V4.1.0 and later
|
// Stop the preview.
mAliLiveEngine.stopPreview();
// Stop ingesting streams.
mAliLiveEngine.stopPush();
// Destroy the AliLiveEngine object.
mAliLiveEngine.destroy();
mAliLiveEngine = null;
|
// Stop the preview.
mAliLivePusher.stopPreview();
// Stop ingesting streams.
mAliLivePusher.stopPush();
// Destroy the AliLivePusher object.
mAliLivePusher.destroy();
mAliLivePusher = null;
|