This topic describes the exceptions and special scenarios that you may encounter when you use Push SDK for Android. This topic also describes how to handle such exceptions and special scenarios.

Handle AlivcLivePushErrorListener callbacks

  • When you receive an onSystemError callback message, which indicates a system error, stop live streaming.
  • When you receive an onSDKError callback message, which indicates an SDK error, destroy the current AlivcLivePusher object and then create another one. Alternatively, you can call the restartPush or restartPushAsync method to restart the current AlivcLivePusher object.
  • You must pay special attention to the fired callbacks that are related to microphone and camera permission issues. The ALIVC_PUSHER_ERROR_SDK_CAPTURE_CAMERA_OPEN_FAILED error code indicates that the mobile app requires permissions to use the microphone. The ALIVC_PUSHER_ERROR_SDK_CAPTURE_MIC_OPEN_FAILED error code indicates that the mobile app requires permissions to use the camera.

Handle AlivcLivePushNetworkListener callbacks

  • An onNetworkPoor callback message is sent to you when the network speed is slow. The message indicates that the network cannot support stream ingest, but the stream is still being ingested and not interrupted. When the network speed resumes to the normal level, an onNetworkRecovery callback message is sent to you. At this point, you can configure custom business logic. For example, you can notify your users of network recovery in a visualized manner on the mobile app UI.
  • The onConnectFail, onReconnectError, or onSendDataTimeout callback is fired when a specific network error occurs. In this case, destroy the current AlivcLivePusher object and then create another one. Alternatively, you can call the reconnectAsync method to reconnect to the network. We recommend that you test the network connectivity and the ingest URL before you perform the reconnection operation.
  • The SDK fires the onReconnectStart callback to reconnect to the network when the SDK receives a reconnection request. The reconnection request may be issued by the SDK or the developer that calls the reconnectAsync method. To reconnect to the network, the mobile app reinitiates a connection to the Real-Time Messaging Protocol (RTMP) server.

    After the RTMP connection is established, an onReconnectSuccess callback message is sent to you. However, the message does not mean that the mobile app resumes stream ingest. Stream ingest may fail to be resumed if a network issue persists. In this case, the SDK keeps reconnecting to the RTMP server.

  • An onPushURLAuthenticationOverdue callback message indicates the expiration of the ingest URL authentication. The SDK sends such a message to you only after you enable ingest URL authentication. An ingest URL contains the auth_key field. This callback is fired 1 minute before the ingest URL expires. After you receive such a message, you must specify a new ingest URL to ensure that the ingest process is not interrupted due to the expiration of the original ingest URL. Sample code:
    String onPushURLAuthenticationOverdue(AlivcLivePusher pusher) {
        return "New ingest URL rtmp://";
    }

Handle AlivcLivePusherBGMListener callbacks

  • The onOpenFailed callback is fired when the background music (BGM) fails to be played. In this case, check whether the audio file and the file path specified for the startBGMAsync method are valid. Then, call the startBGMAsync method to replay the BGM.
  • The onDownloadTimeout callback is fired when the BGM playback times out. This issue generally occurs when the BGM is specified by using an online URL. This callback instructs the streamer to check the status of the network. You can call the startBGMAsync method to replay the BGM.

Handle network disconnection

  • Short-period network disconnection and network switchover: The SDK attempts to reconnect to the network when a network fluctuation or a network switchover occurs. You can use the AlivcLivePushConfig class to specify the reconnection timeout period and the maximum number of reconnection attempts allowed. After the SDK reconnects to the network, stream ingest is resumed. If you use ApsaraVideo Player, we recommend that you perform a reconnection operation 5 seconds after you receive a timeout notification.
  • Long-period network disconnection: The SDK fails to reconnect to the network if a reconnection request times out or the number of reconnection attempts exceeds the upper limit. In this case, the onReconnectError callback is fired. After the network is recovered, call the reconnectAsync method to reconnect the SDK to the network. You must also reconnect the SDK to ApsaraVideo Player.
    • We recommend that you externally monitor the network.
    • Use the server to handle communication failures between the streamer and player. For example, when network disconnection occurs on the streamer, the server receives a callback message of stream ingest interruption from Alibaba Cloud CDN. The server pushes the callback message to the player. Then, the player takes relevant measures to handle the stream ingest interruption. The server uses the same procedure to resume stream ingest.
    • Stop and then restart ApsaraVideo Player to reconnect the player to the ingest URL. To achieve this objective, call the stop and prepareAndPlay methods in sequence.
      mPlayer.stop();
      mPlayer.prepareAndPlay(mUrl);
      Note For more information about ApsaraVideo Player, see Implementation.

Switch the mobile app to the background or lock the screen

  • When the mobile app is switched to the background or the screen is locked, you can call the pause() or resume() method of the AlivcLivePusher class to pause or resume stream ingest.
  • For non-system audio and video calls, the SDK continues recording and ingesting the audio stream. You can call the mAlivcLivePusher.setMute() method to specify whether to enable audio recording when the mobile app is switched to the background or your screen is locked. You can set the setMute field to true or false.

Set bitrates for ingested streams

The SDK supports dynamic bitrate conversion. You can use the AlivcLivePushConfig class to change the default bitrate. Different services require different video quality. The resolution, smoothness, and definition of an output video vary based on the bitrate of the ingested stream.
  • Video definition: The larger the bitrate of the ingested stream is, the higher the video definition is. We recommend that you specify a large bitrate to ensure the playback of high-definition videos.
  • Video smoothness: The larger the bitrate of the ingested stream is, the higher network bandwidth is required. A large bitrate with low network bandwidth may affect the smoothness of the videos.