Prebuilt libraries support
react-native-audio-api can link a number of prebuilt third-party libraries that are downloaded at build time. They enable additional decoding and streaming features, but also add several megabytes to the resulting application binary, so each one can be toggled with a build option.
| Library set | Default | Option | What it adds |
|---|---|---|---|
FFmpeg (libavcodec, libavformat, libavutil, libswresample) | off | enableFFmpeg | Remote URL streaming (HTTP byte ranges), HLS (.m3u8), remote URL metadata — see Runtime flags. |
Static libs (libopus, libopusfile, libogg, libvorbis, libvorbisenc, libvorbisfile) | on | disableStaticExternalLibs | Decoding ogg, opus, oga files |
The options are independent and can be combined.
Leaving FFmpeg off (the default) and setting disableStaticExternalLibs can shave several MB off the final app size across all ABIs / device slices. Pick the set of formats you actually need and turn the rest off.
Apps that would like to decode HLS or make use of URL streaming have to enable it explicitly (see below). Use isFfmpegEnabled to branch at runtime.
Setting the options
Every build (CocoaPods, Swift Package Manager and Gradle) reads the
options from a react-native-audio-api section of the app's package.json. In an Expo app, pass
them as Expo plugin options instead and expo prebuild
writes that section for you.
- Expo
- React Native
app.json / app.config.js:
"plugins": [
[
"react-native-audio-api",
{
"enableFFmpeg": true,
"disableStaticExternalLibs": false
}
]
]
The app's package.json:
"react-native-audio-api": {
"enableFFmpeg": true,
"disableStaticExternalLibs": false
}
After changing them:
- Expo
- React Native
Run npx expo prebuild. It updates the package.json section from the plugin options and then runs pod install.
- CocoaPods: run
pod install. - Swift Package Manager: run
npx react-native spminios. If the app was already built, reset the package cache first. - Android: just rebuild. Gradle reads the file on every build.
Enabling FFmpeg
- Expo
- React Native
app.json / app.config.js:
"plugins": [
[
"react-native-audio-api",
{
"enableFFmpeg": true
}
]
]
The app's package.json:
"react-native-audio-api": {
"enableFFmpeg": true
}
With FFmpeg enabled, the FFmpeg binaries are downloaded during pod install / Swift package resolution / the first Gradle build and linked into the app. FFmpeg is distributed under the LGPL — see THIRD_PARTY.md in the repository for the notice that applies to FFmpeg-enabled builds.
Disabling other external libraries
- Expo
- React Native
app.json / app.config.js:
"plugins": [
[
"react-native-audio-api",
{
"disableStaticExternalLibs": true
}
]
]
The app's package.json:
"react-native-audio-api": {
"disableStaticExternalLibs": true
}
This removes the bundled Opus / Ogg / Vorbis static libraries. With this option enabled, attempts to decode .ogg, .opus, or .oga files through AudioContext.decodeAudioData (or any other decoding path) will return an error — those formats are handled inside miniaudio via the now-disabled custom backends.