This topic describes the API operations that are encapsulated in the AliLiveSDK for Android and the configuration list.

API

Based on features, API operations are classified into basic operations, basic AliLiveEngine operations, and basic Real-Time Communication (RTC)-based stream pulling operations. The following tables describe the API operations based on features.

Table 1. Basic operations
Operation Description Class and description
getSdkVersion Queries the version of the AliLiveSDK for Android. AliLiveEngine: the core class that is used to push streams. It can be used to push streams over Real-Time Messaging Protocol (RTMP) and RTC, pull streams over RTC, render videos, and enable or disable beautification. It is the most important class of the AliLiveSDK for Android.
create Creates an object of the AliLiveEngine class.
destroy Destroys the AliLiveEngine object.
setRtsCallback Sets the callback for stream push over RTC.
setStatsCallback Sets the callback for data statistics during stream push.
setStatusCallback Sets the callback for the stream push status.
setNetworkCallback Sets the callback for the network status during stream push.
setVidePreProcessDelegate Sets the callback for video preprocessing.
setLogDirPath Sets the path for storing the log files of the AliLiveSDK for Android. To prevent log loss, you must call this operation before other API operations. In addition, make sure that the specified path exists and is writable.
setLogLevel Sets the log level.
Table 2. Basic AliLiveEngine operations
Operation Description Class and description
createRenderView Creates a render view. AliLiveEngine: the core class that is used to push streams. It can be used to push streams over Real-Time Messaging Protocol (RTMP) and RTC, pull streams over RTC, render videos, and enable or disable beautification. It is the most important class of the AliLiveSDK for Android.
startPreview Starts the preview. This operation is called on the streamer side.
stopPreview Stops the preview. This operation is called on the streamer side.
pausePush Stops the camera streamand pushs standby streams. This operation is supported only for stream push over RTMP. You must call the startPush operation before the pausePush operation to prevent an invalid call order.
resumePush Enables the camera to collect live streams again and stops pushing standby streams. This operation is supported only for stream push over RTMP. You must call the pausePush operation before the resumePush operation to prevent an invalid call order.
startPush Starts to push streams.
stopPush Stops pushing streams.
ispushing Queries whether streams are being pushed.
getpushUrl Queries the current push URL.
Table 3. Basic RTC-based stream pulling operations
Operation Description Class and description
subscribeStream Subscribes to the video streams of the member who requests a RTC stream. AliLiveEngine: the core class that is used to push streams. It can be used to push streams over Real-Time Messaging Protocol (RTMP) and RTC, pull streams over RTC, render videos, and enable or disable beautification. It is the most important class of the AliLiveSDK for Android.
unSubscribeStream Unsubscribes from the video streams of the member who requests a RTC stream.
renderRemoteStreamWithView Sets the render view for the video streams of the member who requests RTC stream.
renderRemoteStreamWithView Sets the render view and drawing parameters for the video streams of the member who requests a RTC stream.
Table 4. Video-related operations
Operation Description Class and description
setPreviewMode Sets the preview mode. AliLiveEngine: the core class that is used to push streams. It can be used to push streams over Real-Time Messaging Protocol (RTMP) and RTC, pull streams over RTC, render videos, and enable or disable beautification. It is the most important class of the AliLiveSDK for Android.
switchCamera Switches between the front camera and the back camera.
getCurrentCameraPosition Queries the current position of the camera.
isCameraOn Queries whether the camera is enabled.
setCameraZoom Sets the zoom factor of the camera and specifies whether to enable the flash.
isCameraFocusPointSupported Queries whether the camera supports manual focus.
isCameraExposurePointSupported Queries whether an exposure point can be set for the camera.
setCameraFocusPoint Sets the manual focus point of the camera.
setCameraExposurePoint Sets an exposure point for the camera.
Table 5. Audio-related operations
Operation Description Class and description
setMute Specifies whether to mute local audio. AliLiveEngine: the core class that is used to push streams. It can be used to push streams over Real-Time Messaging Protocol (RTMP) and RTC, pull streams over RTC, render videos, and enable or disable beautification. It is the most important class of the AliLiveSDK for Android.
isAudioOnly Queries whether the pushed streams are audio-only streams.
enableSpeakerphone Sets the headset or speaker as the audio output device.
isEnableSpeakerphone Queries whether the headset or speaker is set as the audio output device.
setRecordingVolume Sets the recording volume.
setPlayoutVolume Sets the playback volume.
enableEarBack Enables in-ear monitoring. To prevent echoes, we recommend that you enable in-ear monitoring after you insert the headset.
setEarBackVolume Sets the headset volume when in-ear monitoring is enabled.
playBGM Plays background music.
stopBGM Stop playing background music.
pauseBGM Pauses the playback of background music.
resumeBGM Resumes the playback of background music.
setBGMVolume Sets the volume of background music.
getBGMDuration Queries the total duration of background music. Unit: milliseconds.
getBGMCurrentPosition Queries the playback progress of background music. Unit: milliseconds.
setBGMPosition Sets the playback position of background music.
setPicthValue Sets the pitch.
setReverbMode Sets the reverberation mode.
setVoiceChangerMode Sets the voice change mode.
Table 6. Beautification-related operations
Operation Description Class and description
getBeautyManager Obtains an object of the AliLiveBeautyManager class. AliLiveEngine: the core class that is used to push streams. It can be used to push streams over Real-Time Messaging Protocol (RTMP) and RTC, pull streams over RTC, render videos, and enable or disable beautification. It is the most important class of the AliLiveSDK for Android.
enable Enables or disables beautification. AliLiveBeautyManager: the class that controls the beautification feature, which can be used to specify a beautification type. Beautification types include skin whitening and skin smoothing.
getEnableType Queries whether beautification is enabled.
setBeautyParam Sets a beautification parameter.
destroy Destroys the beautification object.
Table 7. Callbacks
Operation Description Class and description
onLiveTotalStats The callback for total statistics. This callback is supported only for stream push over RTC. StatsCallback: the callback class for real-time statistics during stream push. This class is called every 2 seconds for stream push over RTC or every 10 seconds for stream push over RTMP.
onLiveLocalVideoStats The callback for the statistics on local videos. This callback is supported for stream push over RTMP or RTC.
onLiveRemoteVideoStats The callback for the statistics on remote videos. This callback is supported only for stream push over RTC.
onLiveRemoteAudioStats The callback for the statistics on remote audio. This callback is supported only for stream push over RTC.
onSubscribeResult The status callback that is fired when you subscribe to a URL. After you call the subscribeStream operation, the stream push engine calls back the subscription status of the URL. In the co-stream scenario, a UID uniquely identifies the stream information of a fan. If you subscribe to the URL of the streams of a fan, you will receive audio and video streams from the fan. RtsCallback: the callback class for the statuses of audio and video streams from a fan that you subscribe to in the co-stream scenario. This class is supported only for stream push over RTC, not stream push over RTMP.
onUnSubscribeResult The status callback that is fired when you unsubscribe from a URL. After you call the unSubscribeStream operation, the stream push engine calls back the subscription status of the URL. In the co-stream scenario, a UID uniquely identifies the stream information of a fan. If you unsubscribe from the URL of the streams of a fan, you will not receive audio and video streams from the fan.
onFirstPacketReceivedWithUid The callback that is fired when the first media data packet is received from the URL that you subscribe to. Call the renderRemoteStreamWithView operation after this callback to render and display video streams.
onFirstRemoteVideoFrameDrawn The callback that is fired when the first video frame of the streams that you subscribe to is displayed.
onLiveSdkError The callback that is fired to notify the application of an error in the AliLiveEngine class. StatusCallback: the callback class for the stream push status. You can use this class to obtain the stream push status during stream push over RTMP or RTC.
onLiveSdkWarning The callback that is fired to notify the application of a warning in the AliLiveEngine class.
onPreviewStarted The callback that is fired when the preview starts.
onPreviewStopped The callback that is fired when the preview stops.
onFirstVideoFramePreviewed The callback that is fired when the first video frame is rendered.
onLivePushStarted The callback that is fired when stream push starts.
onLivePushStopped The callback that is fired when stream push stops.
onAudioFocusChanged The callback that is fired when the audio focus changes.
onBGMStateChanged The callback for the audio playback status.
onTexture The callback that is fired in an OpenGL thread to process the collected images. For example, you can beautify the collected images. AliLiveVideoPreProcessCallback: the callback class for video preprocessing. You can use this class to customize the parameters for video image processing. For example, you can customize beautification parameters.
onTextureDestroy The callback that is fired in an OpenGL thread to destroy the texture.
onVideoData The callback for real-time video data that is collected.
onNetworkPoor The callback that is fired when the network bandwidth is low. NetworkCallback: the callback class for network status changes during stream push. It can be used to notify the access party of the network status of the current stream push engine.
onNetworkStatusChange The callback for network status changes. This callback is fired when the network type changes or the network is interrupted. For example, this callback is fired if the network is switched from the Wi-Fi network to the 4G network.
onConnectRecovery The callback that is fired when the network is recovered.
onReconnectStart The callback that is fired when the stream push engine starts to reconnect to the network. In cases of low network bandwidth, stream push may be interrupted. Then, the stream push engine tries to reconnect to the network. This callback is fired in this case.
onConnectionLost The callback that is fired when the stream push process of the stream push engine is interrupted.
onReconnectSuccess The callback that is fired when the stream push engine reconnects to the network and resumes stream push.
onReconnectFail The callback that is fired when the stream push engine fails to reconnect to the network.

Configurations list

  • AliLiveConfig: the class that ApsaraVideo Live SDK provides to set the initialization parameters for stream push over RTMP and RTC. When you create a live streaming engine, you must pass objects of the class as parameters. You must set the parameters before stream push. The parameters do not take effect if you set them after stream push.
    Parameter Type Default value Description
    accountId String NULL The ID that is generated when you activate HTTPDNS and bound to your Alibaba Cloud account. This parameter is required in the co-stream scenario.
    rtmpConfig AliLiveRTMPConfig NULL The parameter settings for stream push over RTMP.
    cameraPosition AliLiveCameraPosition AliLiveCameraPositionFront The position of the camera.
    audioOnly boolean false Specifies whether audio-only streams are pushed in the co-stream scenario.
    autoFocus boolean false Specifies whether to support autofocus.
    videoPushProfile AliLiveVideoPushProfile AliLiveVideoProfile_540P The resolution of the pushed video streams.
    videoFPS int 20 The frame rate of the video.
    enableHighDefPreview boolean false Specifies whether to enable high-definition preview. If the resolution of the collected video streams is lower than or equal to 720p, the video streams are previewed at a resolution of 720p. If the resolution of the collected video streams is higher than 720p, the video streams are previewed at the actual resolution.
    enableVideoEncoderHWAcceleration boolean true Specifies whether to enable hardware encoding for videos.
    enableVideoDecoderHWAcceleration boolean true Specifies whether to enable hardware decoding for videos.
    videoGopSize AliLivePushVideoEncodeGOP AliLivePushVideoEncodeGOP_2 The size of the group of pictures (GOP). Unit: seconds.
    pauseImage Bitmap NULL The image that is pushed when an application is moved to the background. In this case, the audience can view only the image. After you specify the image, call the pausePush operation to push the image.
    videoRenderMode AliLiveRenderMode AliLiveRenderModeAuto The video display mode.
    pushMirror AliLiveRenderMirrorMode AliLiveRenderMirrorModeOnlyFront The mirroring mode.
    flash boolean false Specifies whether to enable the flash.
    zoom float 1.0 The zoom factor of the video image.
    extra String NULL The auxiliary field that helps you troubleshoot SDK issues based on logs. You can specify the URL of the video streams of the member who joins in the live stream in this parameter.
  • AliLiveRTMPConfig: the class that ApsaraVideo Live SDK provides to set the initialization parameters for stream push over RTMP. When you create a live streaming engine, you must pass objects of the class as parameters. You must set the parameters before stream push. The parameters do not take effect if you set them after stream push.
    Parameter Type Default value Description
    enableAudioHWAcceleration boolean false Specifies whether to enable software encoding for audio.
    videoInitBitrate int 1000 The initial bitrate of the video before encoding. Unit: Kbit/s.
    videoTargetBitrate int 1500 The destination bitrate of the video after encoding. Unit: Kbit/s.
    videoMinBitrate int 600 The minimum bitrate of the video. Unit: Kbit/s.
    audioChannel AliLivePushAudioChannel AliLivePushAudioChannel_1 The number of audio channels.
    audioSampleRate AliLivePushAudioSampleRate AliLivePushAudioSampleRate44100 The audio sample rate.
    audioEncoderProfile AliLiveAudioEncoderProfile AliLiveAudioEncoderProfile_AAC_LC The audio encoding format.
    autoReconnectRetryCount int 5 The number of automatic reconnection attempts during stream push.
    autoReconnectRetryInterval int 1000 The interval between two consecutive automatic reconnection attempts during stream push. Unit: milliseconds.

Basic operations

  • getSdkVersion: queries the version of the AliLiveSDK for Android.
    static String getSdkVersion()

    Return result

    The version of the AliLiveSDK for Android is returned.

  • create: creates an object of the AliLiveEngine class.
    static AliLiveEngine create(Context context, AliLiveConfig config)

    Parameters

    Parameter Type Description
    context Context The context.
    config AliLiveConfig The live streaming configuration.

    Return result

    An object of the AliLiveEngine class is returned.

  • destroy: destroys the stream push object.
    void destroy()
  • setRtsCallback: sets the callback for stream push over RTC.
    void setRtsCallback(AliLiveCallback.RtsCallback rtsCallback)

    Parameters

    Parameter Type Description
    rtsCallback RtsCallback The callback for stream push over RTC.
  • setStatsCallback: sets the callback for data statistics during stream push.
    void setStatsCallback(AliLiveCallback.StatsCallback statsCallback)

    Parameters

    Parameter Type Description
    statsCallback statsCallback The callback for data statistics during stream push.
  • setStatusCallback: sets the callback for the stream push status.
    void setStatusCallback(AliLiveCallback.StatusCallback statusCallback)

    Parameters

    Parameter Type Description
    statusCallback StatusCallback The callback for the stream push status.
  • setNetworkCallback: sets the callback for the network status during stream push.
    void setNetworkCallback(AliLiveCallback.NetworkCallback networkCallback)

    Parameters

    Parameter Type Description
    networkCallback NetworkCallback The callback for the network status during stream push.
  • setVidePreProcessDelegate: sets the callback for video preprocessing.
    void setVidePreProcessDelegate(AliLiveCallback.AliLiveVideoPreProcessCallback callback)

    Parameters

    Parameter Type Description
    callback AliLiveVideoPreProcessCallback The callback for video preprocessing.
  • setLogDirPath: sets the path for storing the log files of the AliLiveSDK for Android. To prevent log loss, you must call this operation before other API operations. In addition, make sure that the specified path exists and is writable.
    int setLogDirPath(String logDirPath)

    Parameters

    Parameter Type Description
    logDirPath String The path for storing the log files of the AliLiveSDK for Android.
  • setLogLevel: sets the log level.
    void setLogLevel(AliLiveConstants.AliLiveLogLevel level)

    Parameters

    Parameter Type Description
    level AliLiveLogLevel The log level.

Basic stream push operations

  • createRenderView: creates a render view.
    AliLiveRenderView createRenderView(boolean overlay)

    Parameters

    Parameter Type Description
    overlay boolean Specifies whether to overlay other SurfaceView views.

    Return result

    A render view is returned.

  • startPreview: starts the preview. This operation is called on the streamer side.
    AliLiveError startPreview(AliLiveRenderView surfaceView)

    Parameters

    Parameter Type Description
    surfaceView AliLiveRenderView The render view.

    Return result

    If a value of NULL is returned, the call is successful. Otherwise, the call fails.

  • stopPreview: stops the preview. This operation is called on the streamer side.
    AliLiveError stopPreview()

    Return result

    If a value of NULL is returned, the call is successful. Otherwise, the call fails.

  • pausePush: stops the camera from collecting live streams and pushs standby streams. You must call the startPush operation before the pausePush operation to prevent an invalid call order.
    void pausePush()
  • resumePush: enables the camera to collect live streams again and stops pushing standby streams. You must call the pausePush operation before the resumePush operation to prevent an invalid call order.
    void resumePush()
  • startPush: starts to push streams.
    AliLiveError startPush(String url)

    Parameters

    Parameter Type Description
    url String The push URL. If the URL starts with rtmp://, streams are pushed over RTMP. If the URL starts with artc://, streams are pushed over RTC.

    Return result

    If a value of NULL is returned, the call is successful. Otherwise, the call fails.

  • stopPush: stops pushing streams.
    AliLiveError stopPush()

    Return result

    If a value of NULL is returned, the call is successful. Otherwise, the call fails.

  • ispushing: queries whether streams are being pushed.
    boolean isPublishing()

    Return result

    If a value of true is returned, streams are being pushed. If a value of false is returned, no streams are being pushed.

  • getPublishUrl: queries the current push URL.
    String getPublishUrl()

    Return result

    The current push URL is returned.

Basic RTC-based stream pulling operations

  • subscribeStream: subscribes to the video streams of the member who requests a RTC stream.
    AliLiveError subscribeStream(String url)

    Parameters

    Parameter Type Description
    url String The URL of the video streams of the member who requests a co-stream that you want to subscribe to. The URL uniquely identifies the stream information of the member.

    Return result

    If a value of NULL is returned, the call is successful. Otherwise, the call fails.

  • unSubscribeStream: unsubscribes from the video streams of the member who requests a RTC stream.
    AliLiveError unSubscribeStream(String url)

    Parameters

    Parameter Type Description
    url String The URL of the video streams of the member who requests a co-stream that you want to unsubscribe from. The URL uniquely identifies the stream information of the member.

    Return result

    If a value of NULL is returned, the call is successful. Otherwise, the call fails.

  • renderRemoteStreamWithView: sets the render view for the video streams of the member who requests a co-stream.
    int renderRemoteStreamWithView(AliLiveRenderView remoteView, String url)

    Parameters

    Parameter Type Description
    remoteView AliLiveRenderView The view for which the video streams need to be rendered.
    url String The unique URL of the video streams of the member who requests a co-stream.

    Return result

    If a value of 0 is returned, the call is successful. If a value of -1 is returned, the call fails.

  • renderRemoteStreamWithView: sets the render view and drawing parameters for the video streams of the member who requests a co-stream.
    int renderRemoteStreamWithView(AliLiveRenderView remoteView, String url, AliLiveConstants.AliLiveRenderMode renderMode,
                                                       AliLiveConstants.AliLiveRenderMirrorMode mirrorMode)

    Parameters

    Parameter Type Description
    remoteView AliLiveRenderView The view for which the video streams need to be rendered.
    url String The unique URL of the video streams of the member who requests a co-stream.
    renderMode AliLiveRenderMode The video rendering mode.
    mirrorMode AliLiveRenderMirrorMode Specifies whether to enable mirroring.

    Return result

    If a value of 0 is returned, the call is successful. If a value of -1 is returned, the call fails.

Video-related operations

  • setPreviewMode: sets the preview mode.
    AliLiveError setPreviewMode(AliLiveConstants.AliLiveRenderMode renderMode, AliLiveConstants.AliLiveRenderMirrorMode mirrorMode)

    Parameters

    Parameter Type Description
    renderMode AliLiveRenderMode The video rendering mode.
    mirrorMode AliLiveRenderMirrorMode Specifies whether to enable mirroring.

    Return result

    If a value of NULL is returned, the call is successful. Otherwise, the call fails.

  • switchCamera: switches between the front camera and the back camera.
    AliLiveError switchCamera()

    Return result

    If a value of NULL is returned, the call is successful. Otherwise, the call fails.

  • getCurrentCameraPosition: queries the current position of the camera.
    AliLiveConstants.AliLiveCameraPosition getCurrentCameraPosition()

    Return result

    The current position of the camera is returned.

  • isCameraOn: queries whether the camera is enabled.
    boolean isCameraOn()

    Return result

    If a value of true is returned, the camera is enabled. If a value of false is returned, the camera is disabled.

  • setCameraZoom: sets the zoom factor of the camera and specifies whether to enable the flash.
    int setCameraZoom(float zoom, boolean flashOn)

    Parameters

    Parameter Type Description
    zoom float The zoom factor.
    flashOn boolean Specifies whether to enable the flash.

    Return result

    If a value of 0 is returned, the call is successful. Otherwise, the call fails.

  • isCameraFocusPointSupported: queries whether the camera supports manual focus.
    boolean isCameraFocusPointSupported()

    Return result

    If a value of true is returned, the camera supports manual focus. If a value of false is returned, the camera does not support manual focus.

  • isCameraExposurePointSupported: queries whether an exposure point can be set for the camera.
    boolean isCameraExposurePointSupported()

    Return result

    If a value of true is returned, an exposure point can be set for the camera. If a value of false is returned, no exposure point can be set for the camera.

  • setCameraFocusPoint: sets the manual focus point of the camera.
    int setCameraFocusPoint(AliLivePoint point)

    Parameters

    Parameter Type Description
    point AliLivePoint The focal point.

    Return result

    If a value of 0 is returned, the call is successful. Otherwise, the call fails.

  • setCameraExposurePoint: sets an exposure point for the camera.
    int setCameraExposurePoint(AliLivePoint point)

    Parameters

    Parameter Type Description
    point AliLivePoint The exposure point.

    Return result

    If a value of 0 is returned, the call is successful. Otherwise, the call fails.

Audio-related operations

  • setMute: specifies whether to mute local audio.
    int setMute(boolean mute)

    Parameters

    Parameter Type Description
    mute boolean Specifies whether to mute local audio. Valid values:
    • true: collects mute frames from the local audio.
    • false: collects frames that are not mute from the local audio.

    Return result

    If a value of 0 is returned, the call is queued up. If a value of -1 is returned, the call is rejected.

  • isAudioOnly: queries whether the pushed streams are audio-only streams.
    boolean isAudioOnly()

    Return result

    If a value of true is returned, the pushed streams are audio-only streams. If a value of false is returned, the pushed streams are not audio-only streams.

  • enableSpeakerphone: sets the headset or speaker as the audio output device.
    int enableSpeakerphone(boolean enable)

    Parameters

    Parameter Type Description
    enable boolean Specifies whether the headset or speaker is set as the audio output device. Valid values:
    • true: The speaker is set as the audio output device.
    • false (default): The headset is set as the audio output device.

    Return result

    If a value of 0 is returned, the call is successful. Otherwise, the call fails.

  • isEnableSpeakerphone: queries whether the headset or speaker is set as the audio output device.
    boolean isEnableSpeakerphone()

    Return result

    If a value of true is returned, the speaker is set as the audio output device. If a value of false is returned, the headset is set as the audio output device.

  • setRecordingVolume: sets the recording volume.
    int setRecordingVolume(int volume)

    Parameters

    Parameter Type Description
    volume int The recording volume. Default value: 100. Valid values:
    • 0: mute.
    • [0,100): The volume is higher than or equal to 0 and lower than 100.
    • (100,400]: The volume is higher than 100 and lower than or equal to 400.

    Return result

    If a value of 0 is returned, the call is successful. Otherwise, the call fails.

  • setPlayoutVolume: sets the playback volume.
    int setPlayoutVolume(int volume)

    Parameters

    Parameter Type Description
    volume int The playback volume. Default value: 100. Valid values:
    • 0: mute.
    • [0,100): The volume is higher than or equal to 0 and lower than 100.
    • (100,400]: The volume is higher than 100 and lower than or equal to 400.

    Return result

    If a value of 0 is returned, the call is successful. Otherwise, the call fails.

  • enableEarBack: enables in-ear monitoring. To prevent echoes, we recommend that you enable in-ear monitoring after you insert the headset.
    int enableEarBack(boolean enable)

    Parameters

    Parameter Type Description
    enable boolean Specifies whether to enable earback.
  • setEarBackVolume: sets the headset volume when in-ear monitoring is enabled.
    int setEarBackVolume(int volume)

    Parameters

    Parameter Type Description
    volume int The headset volume when in-ear monitoring is enabled.
  • playBGM: plays background music.
    int playBGM(String path, boolean publish, boolean loop)

    Parameters

    Parameter Type Description
    path String The path for storing on-premises music files. The music files must be in the MP3 or WAV format, and the path cannot contain Chinese characters.
    publish boolean Specifies whether to push streams. Valid values:
    • true: pushs streams to remote users.
    • false: plays the music only on the local side and does not push streams to remote users.
    loop boolean Specifies whether to enable loop playback. Valid values:
    • true: enables loop playback.
    • false: disables loop playback.
  • stopBGM: stops playing background music.
    int stopBGM()
  • pauseBGM: pauses the playback of background music.
    int pauseBGM()
  • resumeBGM: resumes the playback of background music.
    int resumeBGM()
  • setBGMVolume: sets the volume of background music.
    int setBGMVolume( int volume)

    Parameters

    Parameter Type Description
    volume int The volume of background music. Valid values:
    • 0: mute.
    • (0,100]: The volume is higher than 0 and lower than or equal to 100.
  • getBGMDuration: queries the total duration of background music. Unit: milliseconds.
    int getBGMDuration()
  • getBGMCurrentPosition: queries the playback progress of background music. Unit: milliseconds.
    int getBGMCurrentPosition()
  • setBGMPosition: sets the playback position of background music.
    int setBGMPosition(int posMs)

    Parameters

    Parameter Type Description
    posMs int The position of the progress bar. Unit: milliseconds.
  • setPicthValue: sets the pitch.
    int setPicthValue(float pitch)

    Parameters

    Parameter Type Description
    pitch float The pitch. Default value: 1.0f. Valid values: 0.5f to 2.0f.
  • setReverbMode: sets the reverberation mode.
    int setReverbMode(AliLiveConstants.AliLiveReverbMode mode)

    Parameters

    Parameter Type Description
    mode AliLiveReverbMode The reverberation mode. Valid values:
    • AliLiveReverbMode_Off: reverberation disabled.
    • AliLiveReverbMode_Vocal_I: vocal I.
    • AliLiveReverbMode_Vocal_II: vocal II.
    • AliLiveReverbMode_Bathroom: reverberation in bathhouses.
    • AliLiveReverbMode_Small_Room_Bright: reverberation in small bright rooms.
    • AliLiveReverbMode_Small_Room_Dark: reverberation in small dark rooms.
    • AliLiveReverbMode_Medium_Room: reverberation in medium rooms.
    • AliLiveReverbMode_Large_Room: reverberation in large rooms.
    • AliLiveReverbMode_Church_Hall: reverberation in church halls.
    • AliLiveReverbMode_Cathedral: reverberation in cathedrals.
  • setVoiceChangerMode: sets the voice change mode.
    int setVoiceChangerMode(AliLiveConstants.AliLiveVoiceChangerMode mode)

    Parameters

    Parameter Type Description
    mode AliLiveVoiceChangerMode The voice change mode. Valid values:
    • AliLiveVoiceChanger_OFF: voice change disabled.
    • AliLiveVoiceChanger_Oldman: changes to the voice of an old man.
    • AliLiveVoiceChanger_Babyboy: changes to the voice of a boy.
    • AliLiveVoiceChanger_Babygirl: changes to the voice of a girl.
    • AliLiveVoiceChanger_Robot: changes to the voice of a robot.
    • AliLiveVoiceChanger_Daimo: changes to the voice of the big devil.
    • AliLiveVoiceChanger_Ktv: changes to the voice in the KTV.
    • AliLiveVoiceChanger_Echo: changes to the echo.

Beautification-related operations

  • getBeautyManager: obtains an object of the AliLiveBeautyManager class.
    AliLiveBeautyManager getBeautyManager()

    Return result

    An object of the AliLiveBeautyManager class is returned.

  • enable: enables or disables beautification.
    void enable(EnableType enableType)

    Parameters

    Parameter Type Description
    enableType EnableType Specifies whether to enable beautification. Valid values:
    • Off (default): disables beautification.
    • Basic: enables basic beautification.
  • getEnableType: queries whether beautification is enabled.
    EnableType getEnableType()

    Return result

    Whether beautification is enabled is returned.

  • setBeautyParam: sets a beautification parameter.
    void setBeautyParam(BeautyParam param, float value)

    Parameters

    Parameter Type Description
    param BeautyParam The beautification parameter. Valid values:
    • SkinBuffing_SkinBuffing: skin smoothing
    • SkinWhiting_SkinWhiting: skin whitening
    value float The value of the beautification parameter. Valid values: 0 to 1.
  • destroy: destroys the beautification object.
    void destroy()

Callbacks

  • onLiveTotalStats: the callback for total statistics. This callback is supported only for stream push over RTC.
    void onLiveTotalStats(AliLiveStats stats)

    Parameters

    Parameter Type Description
    stats AliLiveStats The real-time statistics.

    The following table describes the parameters in the real-time statistics.

    Parameter Type Description
    sentKbitrate long The bitrate of all data that is sent. Unit: Kbit/s. This parameter is to be added to the statistics.
    rcvdKbitrate long The bitrate of all data that is received. Unit: Kbit/s. This parameter is to be added to the statistics.
    sentBytes long The total amount of data that is sent. Unit: byte. This parameter is to be added to the statistics.
    rcvdBytes long The total amount of data that is received. Unit: byte. This parameter is to be added to the statistics.
    videoRcvdKbitrate long The bitrate of the sent videos. Unit: Kbit/s. This parameter is to be added to the statistics.
    videoSentKbitrate long The bitrate of the received videos. Unit: Kbit/s. This parameter is to be added to the statistics.
    callDuration long The duration of the co-stream. Unit: seconds. This parameter is to be added to the statistics.
    cpuUsage float The CPU utilization. Unit: %. This parameter is to be added to the statistics.
  • onLiveLocalVideoStats: the callback for the statistics on local videos. This callback is supported for stream push over RTMP or RTC.
    void onLiveLocalVideoStats(AliLiveLocalVideoStats localVideoStats)

    Parameters

    Parameter Type Description
    localVideoStats AliLiveLocalVideoStats The statistics on local videos.

    The following table describes the parameters in the statistics on local videos.

    Parameter Type Description
    track AliLiveVideoTrack The track type of the video streams. This parameter is to be added to the statistics.
    sentBitrate int The bitrate of local videos that are sent.
    sentFps int The frame rate of local videos that are sent.
    encodeFps int The frame rate of video encoding.
  • onLiveRemoteVideoStats: the callback for the statistics on remote videos. This callback is supported only for stream push over RTC.
    void onLiveRemoteVideoStats(AliLiveRemoteVideoStats remoteVideoStats)

    Parameters

    Parameter Type Description
    remoteVideoStats AliLiveRemoteVideoStats The statistics on remote videos.

    The following table describes the parameters in the statistics on remote videos.

    Parameter Type Description
    userId String The ID of the remote user.
    track AliLiveVideoTrack The track type of the video streams.
    width int The width of the remote videos.
    height int The height of the remote videos.
    decodeFps int The frame rate of video decoding.
    renderFps int The frame rate of video rendering.
    frozenTimes int The number of stuttering times.
  • onLiveRemoteAudioStats: the callback for the statistics on remote audio. This callback is supported only for stream push over RTC.
    void onLiveRemoteAudioStats(AliLiveRemoteAudioStats remoteAudioStats)

    Parameters

    Parameter Type Description
    remoteAudioStats AliLiveRemoteAudioStats The statistics on remote audio.

    The following table describes the parameters in the statistics on remote audio.

    Parameter Type Description
    userId String The ID of the remote user.
    track AliLiveAudioTrack The track type of the audio streams.
    audioLossRate int The frame loss rate of the audio streams in the callback period.
    rcvdBitrate int The instantaneous bitrate of the received audio streams. Unit: Kbit/s.
    totalFrozenTimes int The cumulative duration of audio stuttering after the remote user joins the channel. Unit: milliseconds.
  • onSubscribeResult: the status callback that is fired when you subscribe to a URL. After you call the subscribeStream operation, the stream push engine calls back the subscription status of the URL. In the co-stream scenario, a UID uniquely identifies the stream information of a fan. If you subscribe to the URL of the streams of a fan, you will receive audio and video streams from the fan.
    void onSubscribeResult(AliLiveResult result, String uid)

    Parameters

    Parameter Type Description
    result AliLiveResult The status of the subscription, which can be a success or failure.
    uid String The UID of the audio and video streams of the member that you subscribe to.
  • onUnSubscribeResult: the status callback that is fired when you unsubscribe from a URL. After you call the unSubscribeStream operation, the stream push engine calls back the subscription status of the URL. In the co-stream scenario, a UID uniquely identifies the stream information of a fan. If you unsubscribe from the URL of the streams of a fan, you will not receive audio and video streams from the fan.
    void onUnSubscribeResult(AliLiveResult result, String uid)

    Parameters

    Parameter Type Description
    result AliLiveResult The status of the subscription, which can be a success or failure.
    uid String The UID of the audio and video streams of the member that you subscribe to.
  • onFirstPacketReceivedWithUid: the callback that is fired when the first media data packet is received from the URL that you subscribe to. Call the renderRemoteStreamWithView operation after this callback to render and display video streams.
    void onFirstPacketReceivedWithUid(String url)

    Parameters

    Parameter Type Description
    url String The URL of the audio and video streams of the member that you subscribe to, which uniquely identifies the member.
  • onFirstRemoteVideoFrameDrawn: the callback that is fired when the first video frame of the streams that you subscribe to is displayed.
    void onFirstRemoteVideoFrameDrawn(String uid, AliLiveConstants.AliLiveVideoTrack videoTrack)

    Parameters

    Parameter Type Description
    uid String The UID of the audio and video streams of the member that you subscribe to.
    videoTrack AliLiveVideoTrack The type of the stream.
  • onLiveSdkError: the callback that is fired to notify the application of an error in the AliLiveEngine class.
    void onLiveSdkError(AliLiveEngine publisher, AliLiveError error)

    Parameters

    Parameter Type Description
    publisher AliLiveEngine The stream push instance.
    error AliLiveError The error message.
  • onLiveSdkWarning: the callback that is fired to notify the application of a warning in the AliLiveEngine class.
    void onLiveSdkWarning(AliLiveEngine publisher, int warn)

    Parameters

    Parameter Type Description
    publisher AliLiveEngine The stream push instance.
    warn int The warning code.
  • onPreviewStarted: the callback that is fired when the preview starts.
    void onPreviewStarted(AliLiveEngine publisher)

    Parameters

    Parameter Type Description
    publisher AliLiveEngine The stream push instance.
  • onPreviewStopped: the callback that is fired when the preview stops.
    void onPreviewStopped(AliLiveEngine publisher)

    Parameters

    Parameter Type Description
    publisher AliLiveEngine The stream push instance.
  • onFirstVideoFramePreviewed: the callback that is fired when the first video frame is rendered.
    void onFirstVideoFramePreviewed(AliLiveEngine publisher)

    Parameters

    Parameter Type Description
    publisher AliLiveEngine The stream push instance.
  • onLivePushStarted: the callback that is fired when stream push starts.
    void onLivePushStarted(AliLiveEngine publisher)

    Parameters

    Parameter Type Description
    publisher AliLiveEngine The stream push instance.
  • onLivePushStopped: the callback that is fired when stream push stops.
    void onLivePushStopped(AliLiveEngine publisher)

    Parameters

    Parameter Type Description
    publisher AliLiveEngine The stream push instance.
  • onAudioFocusChanged: the callback that is fired when the audio focus changes.
    void onAudioFocusChanged(int focusChange)

    Parameters

    Parameter Type Description
    focusChange int For more information, see the definition of android.media.AudioManager in the source code of Android.
  • onBGMStateChanged: the callback for the audio playback status.
    void onBGMStateChanged(AliLiveEngine publisher, AliLiveConstants.AliLiveAudioPlayingStateCode playState,
                                          AliLiveConstants.AliLiveAudioPlayingErrorCode errorCode)

    Parameters

    Parameter Type Description
    publisher AliLiveEngine The stream push instance.
    playState AliLiveAudioPlayingStateCode The playback status.
    errorCode AliLiveAudioPlayingErrorCode The error code about the playback status.
  • onTexture: the callback that is fired in an OpenGL thread to process the collected images. For example, you can beautify the collected images.
    int onTexture(int textureId, int width, int height, int stride, int rotate)

    Parameters

    Parameter Type Description
    textureId int The ID of the texture.
    width int The width of the texture.
    height int The height of the texture.
    stride int The stride.
    rotate int The rotation angle of the texture.
  • onTextureDestroy: the callback that is fired in an OpenGL thread to destroy the texture.
    int onTextureDestroy()
  • onVideoData: the callback for real-time video data that is collected.
    void onVideoData(long dataFrameY, long dataFrameU, long dataFrameV, AliLiveConstants.AliLiveImageFormat format, int width, int height, int strideY, int strideU, int strideV, int rotate)

    Parameters

    Parameter Type Description
    dataFrameY long The Y component.
    dataFrameU long The U component.
    dataFrameV long The V component.
    format AliLiveImageFormat The format of the video image.
    width int The width of the video image.
    height int The height of the video image.
    strideY int The Y stride.
    strideU int The U stride.
    strideV int The V stride.
    rotate int The rotation angle.
  • onNetworkPoor: the callback that is fired when the network bandwidth is low.
    void onNetworkPoor()
  • onNetworkStatusChange: the callback for network status changes. This callback is fired when the network type changes or the network is interrupted. For example, this callback is fired if the network is switched from the Wi-Fi network to the 4G network.
    void  void onNetworkStatusChange(AliLiveConstants.AliLiveNetworkStatus status)()

    Parameters

    Parameter Type Description
    status AliLiveNetworkStatus The network type or status. Valid values:
    • 4G
    • Wi-Fi
    • No network
  • onConnectRecovery: the callback that is fired when the network is recovered.
    void onConnectRecovery()
  • onReconnectStart: the callback that is fired when the stream push engine starts to reconnect to the network. In cases of low network bandwidth, stream push may be interrupted. Then, the stream push engine tries to reconnect to the network. This callback is fired in this case.
    void onReconnectStart()
  • onConnectionLost: the callback that is fired when the stream push process of the stream push engine is interrupted.
    void onConnectionLost()
  • onReconnectSuccess: the callback that is fired when the stream push engine reconnects to the network and resumes stream push.
    void onReconnectSuccess()
  • onReconnectFail: the callback that is fired when the stream push engine fails to reconnect to the network.
    void onReconnectFail()