Expo Plugin
The react-native-video library provides an Expo plugin to simplify the integration and configuration of specific features into your Expo project.
Installation
To use the Expo plugin, you need to add it to your app's configuration file (app.json or app.config.js).
{
"expo": {
"plugins": [
[
"react-native-video",
{
"enableAndroidPictureInPicture": true,
"enableBackgroundAudio": true,
"androidExtensions": {
"useExoplayerDash": true,
"useExoplayerHls": true
}
}
]
]
}
}
export default {
plugins: [
[
'react-native-video',
{
enableAndroidPictureInPicture: true,
enableBackgroundAudio: true,
androidExtensions: {
useExoplayerDash: true,
useExoplayerHls: true,
},
},
],
],
};
Configuration Options
The plugin accepts an optional configuration object with the following properties:
enableAndroidPictureInPicture (optional)
- Type:
boolean - Default:
false - Description: Enables Picture-in-Picture (PiP) mode on Android. This will apply the necessary configurations to your Android project.
enableBackgroundAudio (optional)
- Type:
boolean - Default:
false - Description: Adds the
audiobackground mode toUIBackgroundModesinInfo.plist, which iOS requires for audio to keep playing while the app is in the background. Android needs no project configuration for this: setplayInBackgroundon the player, which uses the playback service the plugin always registers (see below).
androidExtensions (optional)
- Type:
object - Default:
{ useExoplayerDash: true, useExoplayerHls: true } - Description: Allows you to specify which Android ExoPlayer extensions to include. This can help reduce the size of your app by only including the extensions you need.
useExoplayerDash(boolean, default:true): Whether to include ExoPlayer's Dash extension.useExoplayerHls(boolean, default:true): Whether to include ExoPlayer's HLS extension.
enableAndroidPlaybackService (optional)
- Type:
boolean - Default:
true - Description: Registers the Android playback service and the foreground service permissions it needs (see below). The player starts this service when
playInBackgroundorshowNotificationControlsis enabled at runtime, so leave this on unless your app uses neither. Setting it tofalsekeeps the two permissions out of your manifest, which also spares you the foreground service declaration in the Play Console.
reactNativeTestApp (optional)
- Type:
boolean - Default:
false - Description: Whether to use
react-native-test-appcompatible mode.
What the plugin changes
Android, unless enableAndroidPlaybackService is false
- Registers
com.twg.video.core.services.playback.VideoPlaybackService(a Media3MediaSessionServicewithandroid:foregroundServiceType="mediaPlayback") inAndroidManifest.xml. - Adds the
android.permission.FOREGROUND_SERVICEandandroid.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACKpermissions.
The player starts this service at runtime when playInBackground or showNotificationControls is enabled, and neither is known at prebuild time, so the service and its permissions are added by default. If your app declares a foreground service type and targets Android 14 or newer, Google Play asks you to describe its use in the Play Console; an app that uses neither feature can opt out with enableAndroidPlaybackService: false.
Android, per option
enableAndroidPictureInPicture: setsandroid:supportsPictureInPicture="true"on.MainActivity.androidExtensions: writesRNVideo_useExoplayerDashandRNVideo_useExoplayerHlstogradle.properties. A key you leave out keeps its default (true).
iOS
enableBackgroundAudio: addsaudiotoUIBackgroundModesinInfo.plist(and removes it when set tofalse).
Usage
Once configured in your app.json or app.config.js, the plugin will automatically apply the necessary native project changes during the prebuild process (e.g., when running npx expo prebuild). No further manual setup is typically required for these features.