Set up error handling

Set up a single place in your application in which to perform error handling in response to the ERROR state.

  1. Implement a callback for PlaybackEventListener.onStateChanged.
  2. In your callback, when the state parameter is PlayerState.ERROR, provide logic to handle all errors.
  3. After the error is handled, reset the MediaPlayer object or load a new media resource.

    When the MediaPlayer object is in the ERROR state, it cannot exit this state until you either reset the MediaPlayer object (via the MediaPlayer.reset method) or load a new media resource (MediaPlayer.replaceCurrentItemMediaPlayer.ReplaceCurrentItem).

For example:
mediaPlayer.addEventListener(MediaPlayer.Event.PLAYBACK, new MediaPlayer.PlaybackEventListener() {
@Override
public void onStateChanged(MediaPlayer.PlayerState state, MediaPlayerNotification notification) {
    if (state == MediaPlayer.PlayerState.ERROR) {
        // handle PSDK error here
    }
}
}