Expo
How do I play audio in the background with react-native-track-player or expo-audio?
We'd start with expo-audio, where you turn on background playback in its config plugin, call setAudioModeAsync with shouldPlayInBackground, and show lock screen controls. Use react-native-track-player when you need things like Android Auto or caching, and note that version 5 needs a paid license for commercial apps.
Updated October 31, 2026
If your audio stops the moment someone locks their phone or switches apps, the player isn’t broken. Phones pause apps in the background unless the app declares that it plays audio, and that takes a setting in your native build plus a couple of calls in your code.
Which one to use
expo-audio is part of Expo SDK 55 and versioned with it. With it you can play files and streams, keep playing in the background, show lock screen controls, and use a playlist API (useAudioPlaylist). We’d start here, since it’s free and you don’t have to track a separate library’s compatibility.
react-native-track-player is built for music and podcast apps, with queues, Android Auto and CarPlay, caching, and preloading. It comes in two versions, and they’re licensed differently. Version 4 (react-native-track-player) is Apache-2.0 licensed and had its last release, 4.1.2, in August 2025. Version 5 (@rntp/player) is a rewrite for React Native’s New Architecture that isn’t backwards compatible with version 4, and while it’s free for personal and educational use, commercial use needs a paid license. Either version includes native code that isn’t in Expo Go, so you’ll need a development build.
How to play audio in the background with expo-audio
-
Install it:
npx expo install expo-audio -
Turn on background playback in
app.json. On iOS this adds theaudiobackground mode, and on Android it adds a media playback foreground service and its permissions:{ "expo": { "plugins": [["expo-audio", { "enableBackgroundPlayback": true }]] } } -
Set the audio mode and show lock screen controls when playback starts:
import { useEffect } from "react"; import { Button } from "react-native"; import { setAudioModeAsync, useAudioPlayer } from "expo-audio"; export function EpisodePlayer({ url }: { url: string }) { const player = useAudioPlayer(url); useEffect(() => { setAudioModeAsync({ playsInSilentMode: true, shouldPlayInBackground: true, interruptionMode: "doNotMix", }); }, []); function play() { player.setActiveForLockScreen(true, { title: "Episode 12", artist: "Our Podcast" }); player.play(); } return <Button title="Play" onPress={play} />; }On Android, the lock screen controls aren’t optional, since playback stops after about 3 minutes in the background without
setActiveForLockScreen, according to Expo’s documentation. -
Make a new build. The plugin changes native settings, and those only take effect in a build of your app, so test in a development build rather than Expo Go.
If you need react-native-track-player
With version 5, the setup in its quick start looks like this:
-
Install it with
npx expo install @rntp/player. -
Add the background mode to
app.jsonunder"ios": { "infoPlist": { "UIBackgroundModes": ["audio"] } }. -
Set up the player once when the app starts, then load tracks and play:
import TrackPlayer from "@rntp/player"; TrackPlayer.setupPlayer({ contentType: "music" }); TrackPlayer.setMediaItems([ { mediaId: "ep-12", url: "https://example.com/ep12.mp3", title: "Episode 12" }, ]); TrackPlayer.play(); -
If you need logic that keeps running in the background, such as saving progress, call
TrackPlayer.registerPlaybackSessionin a file that loads at startup, not inside a component.
Guides written for version 4 use registerPlaybackService, add, and updateOptions, while version 5’s quick start uses registerPlaybackSession, setMediaItems, and setCommands, so match the guide to the version you installed.
How you know it works
If you start playback in a build on a real phone and lock the screen, the audio keeps going, and the lock screen shows your title with play and pause controls. On Android, a media notification also appears. Since the Android cutoff is about 3 minutes, leave an Android phone locked for longer than that to be sure.
If it still stops
If it stops right away, check that you’re not testing in Expo Go and that you rebuilt after adding the plugin. If it’s silent on an iPhone with the mute switch on, set playsInSilentMode: true. And if it stops when the user leaves the screen, that’s because a player from useAudioPlayer is released when the component unmounts. For a player that outlives one screen, create it with createAudioPlayer and call release() yourself when you’re done with it.
Ask the agent
If your app is in Draftbit, paste this into the agent, and it can read your code and make the change for you.
Make our audio keep playing when the app goes to the background or the phone locks, using expo-audio. Show lock screen controls with the track title and artist, and set it up for both iPhone and Android.