Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/afkcodes/react-native-audio-pro/llms.txt

Use this file to discover all available pages before exploring further.

React Native Audio Pro separates error reporting into two independent paths. A PLAYBACK_ERROR event is a non-fatal signal that something went wrong during playback — the player may still be usable and may retry on its own. A STATE_CHANGED event carrying state: AudioProState.ERROR is an unrecoverable failure: the player has been cleared and must be restarted. Understanding which path fired (and whether they appear together) is the foundation of a solid error-handling strategy.

Two Error Paths

1. PLAYBACK_ERROR Event

Emitted independently when a non-fatal error occurs. The player is not necessarily stopped — it may already be retrying. This is the right place to log the error, update UI, or attempt a URL refresh.
AudioPro.addEventListener((event) => {
  if (event.type === AudioProEventType.PLAYBACK_ERROR) {
    const { error, errorCode, recoverable, cause, index } = event.payload ?? {};
    console.warn('Playback error:', error, 'code:', errorCode);
  }
});

2. STATE_CHANGED with state: AudioProState.ERROR

Emitted when the player enters an unrecoverable failure and resets its internal state. After receiving this event you must re-load your queue and restart playback from scratch.
AudioPro.addEventListener((event) => {
  if (
    event.type === AudioProEventType.STATE_CHANGED &&
    event.payload?.state === AudioProState.ERROR
  ) {
    console.error('Player entered unrecoverable ERROR state');
    // Re-load your queue and call AudioPro.play() to restart
  }
});
PLAYBACK_ERROR and STATE_CHANGED: ERROR are independent — one does not imply the other. A PLAYBACK_ERROR with recoverable: true may fire without any accompanying state change, and an unrecoverable STATE_CHANGED: ERROR may arrive with or without a preceding PLAYBACK_ERROR. Always handle both.

AudioProPlaybackErrorPayload

The payload attached to a PLAYBACK_ERROR event contains the following fields:
FieldTypeDescription
errorstringHuman-readable error message.
errorCodeAudioProErrorCode | numberNumeric code identifying the error category (see below).
recoverablebooleantrue if the player may still be usable and could retry automatically.
causestring (optional)Optional underlying exception message from the native layer.
indexnumber (optional)Queue index of the track that caused the error, if known.

AudioProErrorCode Reference

Error codes are grouped by category so you can apply broad recovery logic without matching every individual code.

Unknown

CodeNameNotes
0UNKNOWNCatch-all for unmapped errors.

Network Errors (1xxx) — typically recoverable

CodeNameNotes
1001NETWORK_TIMEOUTRequest timed out.
1002NETWORK_FAILEDGeneral network failure.
1003TIMEOUTGeneric timeout.
1004IO_UNSPECIFIEDUnspecified I/O error.
1005INVALID_CONTENT_TYPEServer returned an unexpected MIME type.

Decoding Errors (2xxx) — typically unrecoverable

CodeNameNotes
2001DECODING_FAILEDAudio decoding failed.
2002AUDIO_TRACK_INIT_FAILEDFailed to initialise the audio track.
2003DECODER_INIT_FAILEDCould not initialise a decoder.
2004DECODER_QUERY_FAILEDDecoder capability query failed.
2005FORMAT_UNSUPPORTEDAudio format is not supported.
2006FORMAT_EXCEEDS_CAPABILITIESFormat exists but exceeds device capabilities.

DRM Errors (3xxx) — typically unrecoverable

CodeNameNotes
3001DRM_UNSPECIFIEDUnspecified DRM error.
3002DRM_SCHEME_UNSUPPORTEDDRM scheme not supported on device.
3003DRM_PROVISIONING_FAILEDDevice provisioning failed.
3004DRM_LICENSE_ACQUISITION_FAILEDCould not acquire a DRM licence.
3005DRM_LICENSE_EXPIREDDRM licence has expired.

Content Errors (4xxx)

CodeNameNotes
4001CONTENT_NOT_FOUNDResource returned 404 or equivalent.
4002BAD_HTTP_STATUSServer returned an unexpected HTTP status code.
4003CONTAINER_MALFORMEDAudio container is corrupt or malformed.
4004MANIFEST_MALFORMEDHLS/DASH manifest could not be parsed.
4005BEHIND_LIVE_WINDOWSeek position falls behind the live window edge.

Reading Error State

Reactively with useAudioPro()

The error field in useAudioPro() is updated whenever a PLAYBACK_ERROR event fires and cleared automatically when the player transitions out of the error state.
import { useAudioPro } from 'react-native-audio-pro';

function ErrorBanner() {
  const { error } = useAudioPro();

  if (!error) return null;

  return (
    <View>
      <Text>Error: {error.error}</Text>
      <Text>Code: {error.errorCode}</Text>
      <Text>{error.recoverable ? 'Recoverable' : 'Unrecoverable'}</Text>
    </View>
  );
}

Imperatively with AudioPro.getError()

Call AudioPro.getError() anywhere outside of a React component — in event handlers, service classes, or background tasks.
const currentError = AudioPro.getError();

if (currentError) {
  console.log('Last error:', currentError.error, '| code:', currentError.errorCode);
}
Error state clears automatically when the player transitions out of the ERROR state — for example when you call play() after recovery. You do not need to clear it manually.

Complete Error-Handling Component

The example below renders an error banner with the error message, code, and recoverability label. For recoverable errors it also offers a retry button.
import React, { useCallback } from 'react';
import { Button, Text, View } from 'react-native';
import {
  AudioPro,
  AudioProErrorCode,
  AudioProState,
  useAudioPro,
} from 'react-native-audio-pro';

export function PlaybackErrorBanner() {
  const { error, state } = useAudioPro();

  const handleRetry = useCallback(() => {
    // Check current state before forcing a retry — the player may already
    // be recovering on its own
    const currentState = AudioPro.getPlaybackState();

    if (
      currentState !== AudioProState.PLAYING &&
      currentState !== AudioProState.LOADING
    ) {
      const activeIndex = AudioPro.getCurrentMediaItemIndex();

      if (activeIndex >= 0) {
        AudioPro.seekToMediaItem(activeIndex);
        setTimeout(() => AudioPro.play(), 100);
      } else {
        AudioPro.play();
      }
    }
  }, []);

  if (!error) return null;

  const isNetworkError =
    typeof error.errorCode === 'number' &&
    error.errorCode >= 1000 &&
    error.errorCode < 2000;

  return (
    <View>
      <Text>
        {error.recoverable ? 'Recoverable error' : 'Unrecoverable error'}
      </Text>

      <Text>{error.error}</Text>

      <Text>
        Code: {error.errorCode ?? AudioProErrorCode.UNKNOWN}
        {isNetworkError ? ' (network)' : ''}
      </Text>

      {error.cause ? <Text>Cause: {error.cause}</Text> : null}

      {error.recoverable && (
        <Button title="Retry" onPress={handleRetry} />
      )}

      {state === AudioProState.ERROR && (
        <Text>Player stopped. Tap retry to reload.</Text>
      )}
    </View>
  );
}
recoverable: true means the native player considers itself still usable and may already be retrying automatically. Call AudioPro.getPlaybackState() before forcing a manual retry — if the state is already PLAYING or LOADING, skip the retry to avoid interrupting the ongoing recovery attempt.

Build docs developers (and LLMs) love