Reputation: 21
I am developing a cross-platform application using Expo and React Native, targeting both iOS and Android. My goal is to enable audio recording that continues even when the app is backgrounded or the device's screen is locked. I prefer to find a solution that avoiding the need to eject and handle native code customization.
Currently, I'm using expo-av for basic audio recording functionalities, but without any background service implementation:
import { Audio } from 'expo-av';
const startRecording = async () => {
await Audio.setAudioModeAsync({
allowsRecordingIOS: true,
playsInSilentModeIOS: true,
staysActiveInBackground: true,
interruptionModeIOS: InterruptionModeIOS.DoNotMix,
shouldDuckAndroid: true,
interruptionModeAndroid: InterruptionModeAndroid.DoNotMix,
playThroughEarpieceAndroid: false,
});
const { recording } = await Audio.Recording.createAsync(
Audio.RecordingOptionsPresets.HIGH_QUALITY
);
await recording.startAsync();
};
const stopRecording = async (recording) => {
await recording.stopAndUnloadAsync();
return recording.getURI();
};
I understand the basic requirements like adding a background mode for iOS and using a Foreground Service for Android. However, I'm looking for guidance on maintained packages or combinations of packages that can handle these tasks within Expo's environment.
I’ve tried several libraries to enable background audio recording within Expo’s managed workflow, but so far haven’t found a solution that meets all the requirements.
Questions:
I'm hoping to find a solution that leverages existing tools and libraries in Expo without resorting to custom native implementations. Any advice or recommendations would be greatly appreciated.
Thank you in advance!
Upvotes: 2
Views: 362
Reputation: 11
For Ios, you need to update your infoPlist by adding
infoPlist: {
NSMicrophoneUsageDescription:
"The app records ...",
UIBackgroundModes: ["audio"],
}
to your config.ios
Upvotes: 1