Queue

MediaItem

Every item in the queue is a MediaItem:

FieldTypeDescription
urlstring \| number \| { uri, headers }Audio source
mediaIdstringUnique identifier (falls back to URL)
titlestringTrack title
artiststringArtist name
albumTitlestringAlbum title
artworkUrlstringArtwork image URL
durationnumberDuration hint in seconds (optional)
isLivebooleanMarks a live stream — disables caching and preloading

Setting the queue

Replace the entire queue and start from a given index:

await TrackPlayer.setMediaItems(items, startIndex?: number);

Set a single item (replaces queue with one track):

await TrackPlayer.setMediaItem(item);

Adding tracks

// Append to end of queue
await TrackPlayer.addMediaItem(item);
await TrackPlayer.addMediaItems(items);

// Insert at a specific index
await TrackPlayer.insertMediaItem(index, item);
await TrackPlayer.insertMediaItems(index, items);

Removing tracks

// Remove by index
await TrackPlayer.removeMediaItem(index);

// Remove a range (inclusive)
await TrackPlayer.removeMediaItems(fromIndex, toIndex);

// Clear the entire queue
await TrackPlayer.clear();

Reordering

await TrackPlayer.moveMediaItem(fromIndex, toIndex);

Replacing a track

await TrackPlayer.replaceMediaItem(index, newItem);

Updating metadata

Useful for live streams where metadata arrives mid-playback (e.g. ICY stream tags):

await TrackPlayer.updateMetadata(index, {
  title: 'Now Playing: Song Title',
  artist: 'Artist Name',
});

Reading queue state

const queue = TrackPlayer.getQueue();
const current = TrackPlayer.getActiveMediaItem();
const index = TrackPlayer.getActiveMediaItemIndex();

All three are synchronous — no await needed.

ende