skip to Main Content

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.

  • expo-av: Provides basic recording, but lacks support for background/lock screen recording.
  • react-native-background-audio-record: Promising, but doesn’t handle background recording reliably and appears outdated.
  • react-native-track-player: Suitable for background playback but lacks support for audio recording.

Questions:

  • How can I configure continuous audio recording in the background, including during lock screen?
  • Are there any maintained libraries or combinations of packages for this case?
  • If no single solution exists, what alternatives do I have within Expo?

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!

2

Answers


  1. For Ios, you need to update your infoPlist by adding

    infoPlist: {
            NSMicrophoneUsageDescription:
              "The app records ...",
            UIBackgroundModes: ["audio"],
          }
    

    to your config.ios

    Login or Signup to reply.
  2. you have any luck with this? I am having the same issue

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search