AMP Android SDK: Error handling

Document created by Orlando Sanchez Martinez Employee on Oct 20, 2017Last modified by Orlando Sanchez Martinez Employee on Oct 20, 2017
Version 5Show Document
  • View in full screen mode

Whenever there is an error, the SDK will fire the PLAYER_EVENT_TYPE_ERROR (more on events handling).

 

It's up to the app how to handle this errors. To ease that handling, the VideoPlayerView class provides these options:

  1. to get an Exception, if one occurred
  2. to get the HTTP error code, if one occurred
  3. to get an AMP defined constant of the error that occurred

 

The following assumes you have correctly registered an IPlayerEventsListener, that would get the PLAYER_EVENT_TYPE_ERROR

To get a human readable name of the error (for logs and others), you can use the com.akamai.media.PlayerEvents.getName(int eventID) method.

 

 

1. Getting an exception

  • This is accomplished via videoPlayerView.getLastException().
  • Most of the times, the returning value will be a subclass of com.akamai.exoplayer2.ExoPlaybackException.

 

2. Getting an HTTP error code

  • This is accomplished via videoPlayerView.getLastHttpErrorCode().
  • In case the error was not HTTP related, this method returns a default int value of -1.

 

3. Getting the AMP defined constant of the error

  • This is accomplished via videoPlayerView.getLastErrorCode().
  • To get a human readable description of it (for logs and others), you can use the com.akamai.media.ErrorEvents.getDescription(int lastErrorCode) method.

 

 

 

Here is a code snippet that shows the use of all the methods described above:

 

@Override
public boolean onPlayerEvent(int eventID) {
   Log.e("EventsTest", PlayerEvents.getName(eventID));
   boolean isError = IPlayerEventsListener.PLAYER_EVENT_TYPE_ERROR == eventID;
   if (isError)
   {
      int lastErrorCode = videoPlayerView.getLastErrorCode();
      int lastHttpErrorCode = videoPlayerView.getLastHttpErrorCode();
      Exception lastException = videoPlayerView.getLastException();

      String errorName = ErrorEvents.getDescription(lastErrorCode);
      String errorMessage = "PLAYER_EVENT_TYPE_ERROR: " + errorName + " (" + lastHttpErrorCode + ") " + lastException.toString();
      Log.e("EventsTest", errorMessage);
   }
   return false;
}

 

If you have any question or comment, reach out to us via email: amp-sdk-support@akamai.com

 

This document is part ofAMP Android SDK 

Attachments

    Outcomes