Custom HTTP headers
Many media servers require an Authorization header, an API key, or a specific user agent. Set them once in configure() and they apply to every remote request the library makes — media fetches, look-ahead cache prefetches, and artwork loads.
import { getTrackPlayer } from 'react-native-queue-player';
await getTrackPlayer().configure({
httpHeaders: {
Authorization: 'Bearer ' + token,
'X-Api-Key': apiKey,
},
userAgent: 'my-app/1.2.3',
});
httpHeaders— a string map applied to every remote HTTP request.userAgent— overrides the default user agent.
Updating headers (e.g. a refreshed token)
configure() rebuilds the player from a clean slate each time it is called, so to rotate an expired token, call configure() again with the new headers, then restore your queue and position:
const player = getTrackPlayer();
const queue = player.getQueue();
const index = player.getCurrentTrackIndex();
await player.configure({ httpHeaders: { Authorization: 'Bearer ' + freshToken } });
await player.setQueue(queue, index);
await player.play();
For long sessions, refresh the token before it expires rather than reacting to a playback error.
Notes
- Headers apply to
http(s)://sources.file://(local) sources don't make network requests. - Other request tuning lives in
PlayerConfig—autoRetries,retryBackoffMs, and (Android)networkTimeoutMs.