Skip to main content
Version: Next

Audio API Expo plugin

What is Audio API Expo plugin​

The Audio API Expo plugin allows to set certain permissions and background audio related settings in developer friendly way.

interface Options {
iosMicrophonePermission?: string;
iosBackgroundMode: boolean;
androidPermissions: string[];
androidForegroundService: boolean;
androidFSTypes: string[];
androidFSStopWithTask: boolean;
}

How to use it?​

Add react-native-audio-api expo plugin to your app.json or app.config.js.

app.json

{
"plugins": [
[
"react-native-audio-api",
{
"iosBackgroundMode": true,
"iosMicrophonePermission": "This app requires access to the microphone to record audio.",
"androidPermissions" : [
"android.permission.MODIFY_AUDIO_SETTINGS",
"android.permission.FOREGROUND_SERVICE",
"android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"
],
"androidForegroundService": true,
"androidFSTypes": [
"mediaPlayback"
]
}
]
]
}

app.config.js

export default {
...
"plugins": [
[
"react-native-audio-api",
{
"iosBackgroundMode": true,
"iosMicrophonePermission": "This app requires access to the microphone to record audio.",
"androidPermissions" : [
"android.permission.MODIFY_AUDIO_SETTINGS",
"android.permission.FOREGROUND_SERVICE",
"android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"
],
"androidForegroundService": true,
"androidFSTypes": [
"mediaPlayback"
]
}
]
]
};

Options​

iosBackgroundMode​

Defaults to true.

Allows the app to play audio in the background on iOS.

iosMicrophonePermission​

Defaults to undefined.

Allows to specify a custom microphone permission message for iOS. If not specified it will be omitted in the Info.plist.

androidPermissions​

Defaults to

[
'android.permission.FOREGROUND_SERVICE',
'android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK'
]

Allows to specify certain android app permissions to apply.

Permissions:

  • android.permission.POST_NOTIFICATIONS - required by Foreground Services on Android 13+ to post notifications.
  • android.permission.FOREGROUND_SERVICE - allows the app to run a Foreground Service.
  • android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK - allows the app to run a Foreground Service specifically for continuous audio or video playback.
  • android.permission.FOREGROUND_SERVICE_MICROPHONE - allows the app to run a Foreground Service specifically for continuous microphone capture from the background.
  • android.permission.MODIFY_AUDIO_SETTINGS - allows the app to modify global audio settings.
  • android.permission.INTERNET - allows applications to open network sockets.
  • android.permission.RECORD_AUDIO - allows an application to record audio.

androidForegroundService​

Defaults to true.

Allows the app to use Foreground Service options specified by the user. It permits the app to play audio in the background on Android.

androidFSTypes​

Allows the user to specify the appropriate Foreground Service type.

Types description:

  • mediaPlayback - continue audio or video playback from the background.
  • microphone - continue microphone capture from the background, such as voice recorders or communication apps.

Runtime prerequisites:

  • Request and be granted the RECORD_AUDIO runtime permission.

androidFSStopWithTask​

Defaults to true.

Controls the android:stopWithTask attribute of the Foreground Service injected by the plugin. With the default value (true), the service stops when the user swipes the app away from the recents screen.

Set it to false to emit android:stopWithTask="false" on the service entry — on task removal the service keeps running, which keeps the app process (and e.g. an in-progress recording) alive.

info

The Foreground Service only exists while a library notification is shown, so this option has an effect only if a notification (e.g. via RecordingNotificationManager.show()) is displayed before the user closes the app. See keeping the recording alive when the app is closed for the full set of requirements.