Player Setup

Configure and initialize the player before any other API calls.

setupPlayer

TrackPlayer.setupPlayer(options?:PlayerConfig):void

Initializes the native player and applies initial options. Must be called once before using any other API. Defaults are defined in TS; native receives a full config. - **Android**: Should be called while the app is in the foreground - Calling twice will throw

FieldTypeDefaultDescription
contentType 'music' | 'speech'Content type hint for the system. Affects audio routing and focus behavior. - 'music': Standard music playback (default) - 'speech': Spoken content like podcasts/audiobooks On iOS this sets the AVAudioSession mode (.default vs .spokenAudio). On Android this sets AudioAttributes contentType (MUSIC vs SPEECH).
handleAudioBecomingNoisy booleanWhether the player should automatically pause when audio output is rerouted (e.g. headphones disconnected). Defaults to true.
autoUpdateMetadataFromStream v5.1.0+booleantrueWhen `true` (default), ICY/ID3 metadata updates the queued MediaItem and Now Playing. When `false`, only Event.MetadataReceived is emitted; call updateMetadata yourself.
audioMixing v5.5.0+'exclusive' | 'mix''exclusive'How this player's audio coexists with other apps' audio. - 'exclusive' (default): interrupts other apps' audio. - 'mix': plays layered over other apps without interrupting them. On iOS this toggles the AVAudioSession `.mixWithOthers` category option. On Android 'mix' holds no audio focus, so the player won't auto-pause for calls or resume afterwards.
cache CacheConfigEnable disk caching and preloading. When set, played audio is written through to a disk cache and the next queue item is automatically preloaded. Previously cached content is served from disk on subsequent plays. On Android this uses Media3's SimpleCache + CacheDataSource. On iOS this uses an AVAssetResourceLoaderDelegate-based streaming cache.
progressSync ProgressSyncConfig
android Partial<AndroidPlayerConfig>

CacheConfig

FieldTypeDefaultDescription
maxSizeBytes number524288000 (500 MB)Maximum disk cache size in bytes. When the cache exceeds this size, least-recently-used items are evicted.
preloading PreloadConfigPreloading configuration. Requires cache to be enabled.

ProgressSyncConfig

FieldTypeDefaultDescription
intervalSeconds number
http { url: string; headers?: Record<string, string> }

The HTTP POST body is JSON with the following shape:

{ "mediaId": "ep-123", "position": 142.5, "duration": 3600.0, "timestamp": 1710000000000 }

This is the same payload emitted by the PlaybackProgressUpdated event. A final tick is always sent on pause or stop.

AndroidPlayerConfig

FieldTypeDefaultDescription
wakeMode * 'none' | 'local' | 'network''none'
skipSilenceEnabled * booleanfalse
taskRemovedBehavior v5.4.0+TaskRemovedBehavior'continue'When the app is removed from recents: `continue` keeps playback; `stop` tears down the service.
notification { channelId: string; channelName: string; smallIcon: string; }Android notification configuration.
cast stringChromecast receiver app ID. When set, Cast support is enabled and the `<OutputDeviceButton>` / `<CastButton>` will filter for this receiver. Use `DEFAULT_CAST_RECEIVER_APP_ID` for Google's Default Media Receiver (no registration required). Omit to disable Cast entirely.

notification is an object with channelId, channelName, and smallIcon (Android resource name, e.g. 'ic_stat_music_note').

taskRemovedBehavior (continue | stop, default continue) controls whether playback survives when the app is swiped from recents.

Example

TrackPlayer.setupPlayer({
  contentType: 'music',
  handleAudioBecomingNoisy: true,
  cache: { maxSizeBytes: 200 * 1024 * 1024 }, // 200 MB
  progressSync: {
    intervalSeconds: 30,
    http: {
      url: 'https://api.example.com/progress',
      headers: { 'Authorization': 'Bearer xxx' },
    },
  },
  android: {
    wakeMode: 'network',
    notification: {
      channelId: 'com.myapp.audio',
      channelName: 'Audio Playback',
      smallIcon: 'ic_notification',
    },
  },
});

destroy

TrackPlayer.destroy():void

Tears down the player and releases all resources. After calling this, you must call `setupPlayer()` again to use the player.

Tears down the player and releases all resources. After calling this, you must call setupPlayer() again to use the player.

TrackPlayer.destroy();

setCommands

Configure which commands appear on the lock screen, notification, and native media session (including Android Auto when the host connects to your playback service).

TrackPlayer.setCommands(commands:RemoteControlConfig):void

Update remote control configuration at runtime. Use this to change which commands appear in the notification/lock screen (e.g., disable skip buttons on a single-item queue). Configures the **native** media session (lock screen, notification, Android Auto). With `handling: 'native'` (default), actions run without JavaScript; on Android config is persisted for the playback service. `handling: 'js'` / `'hybrid'` emit remote events to `addEventListener` / `registerBackgroundEventHandler` on the phone only — Android Auto and CarPlay do not run the JS runtime; use native handling or native extensions for in-car custom behavior.

Remote control and media-session command configuration (lock screen, notification, Android Auto, and similar surfaces). This configures **native** behavior. With `handling: 'native'` (default), actions run without JavaScript; on Android, config is persisted for the playback service. `handling: 'js'` / `'hybrid'` emit events to `addEventListener` / `registerBackgroundEventHandler` on the phone only — Android Auto and CarPlay do not run the React Native JS runtime for transport controls; use native handling or native extensions for in-car custom behavior.

FieldTypeDefaultDescription
capabilities * PlayerCommand[]Which commands are available in the notification/remote controls and media session.
handling RemoteControlHandling'native'Who handles remote control button presses.
perCommandHandling PerCommandHandlingPer-command handling overrides (only used when handling is 'hybrid').
forwardInterval numberInterval in seconds for the skip-forward button (default: 15). Only used when capabilities includes SkipForward and handling is native or hybrid native for that command.
backwardInterval numberInterval in seconds for the skip-backward button (default: 15). Only used when capabilities includes SkipBackward and handling is native or hybrid native for that command.

In-car behavior: Remote controls in-car.

Available PlayerCommand values: PlayerCommand.Seek, PlayerCommand.PlayPause, PlayerCommand.Next, PlayerCommand.Previous, PlayerCommand.Stop, PlayerCommand.SkipForward, PlayerCommand.SkipBackward.

import { PlayerCommand } from '@rntp/player';

TrackPlayer.setCommands({
  capabilities: [
    PlayerCommand.PlayPause,
    PlayerCommand.Next,
    PlayerCommand.Previous,
    PlayerCommand.Seek,
  ],
  forwardInterval: 30,
  backwardInterval: 15,
});

updateProgressSyncHeaders

TrackPlayer.updateProgressSyncHeaders(headers:Record<string, string>):void

Update the HTTP headers used for progress sync POST requests.

Update the HTTP headers used for progress sync POST requests at runtime — useful when auth tokens refresh.

TrackPlayer.updateProgressSyncHeaders({ Authorization: 'Bearer new-token' });

Caching

When cache is configured, audio is stored locally after the first download. Subsequent plays of the same URL are served from cache without a network request.

TrackPlayer.setupPlayer({
  cache: { maxSizeBytes: 500 * 1024 * 1024 }, // 500 MB
});
TrackPlayer.clearCache():void

Clears the on-disk audio cache. For debugging; next playback will re-download.

TrackPlayer.clearCache();
The useProgress hook exposes a cached field (in seconds) indicating how much of the current track is stored locally. Caching works regardless of whether the server provides a Content-Length header — the total size is determined when the download completes.

Preloading

Preloading downloads tracks to cache before they’re played, reducing gaps between tracks and enabling instant playback from browse screens.

Auto preloading

Automatically preload the next tracks in the queue:

FieldTypeDefaultDescription
window number0 (disabled)Auto-preload next N tracks in queue. Preloading starts when the current item is live, a local file, or fully cached on disk. It also re-evaluates when the queue changes (items added, removed, replaced, or reordered).
TrackPlayer.setupPlayer({
  cache: {
    preloading: {
      window: 1, // preload next 1 track
    },
  },
});

Auto preloading starts when the current track is fully cached, is a live stream, or is a local file. It also re-evaluates when the queue changes (items added, removed, replaced, or reordered). For on-demand streams, preloading waits until the current track finishes downloading to avoid competing for bandwidth.

Manual preloading

Preload any track on demand — useful for browse screens, recommendations, or any UI where the user might play a track:

TrackPlayer.preload(item:MediaItem,options?:PreloadOptions):void

Preload a media item into the cache for instant playback later. Works independently of the queue — any future play of the same URL will be a cache hit.

TrackPlayer.cancelPreload(item:MediaItem):void

Cancel an in-progress preload for the given media item. Partial data remains in cache.

FieldTypeDefaultDescription
duration numberTarget duration in seconds. If omitted, preloads the entire file.
// Preload entire file
TrackPlayer.preload(mediaItem);

// Preload approximately 30 seconds
TrackPlayer.preload(mediaItem, { duration: 30 });

// Cancel an in-progress preload
TrackPlayer.cancelPreload(mediaItem);

Manual preloading works independently of the queue. The cache is keyed by URL, so any future play of the same URL will be a cache hit.

Preloading requires cache to be configured in setupPlayer.
ende