Audio record bug, Another app is interfering

It happen on iOS.

"expo": "^35.0.0",
"expo-av": "~7.0.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",

I use the recording function of Expo, but I feel that this function is interfering with other applications.

  1. Record with our app. Success.
  2. For example, play music with Spotify or AppleMusic.
  3. Record again with our app. It ’s really jammy.

Is there a workaround for this issue?

Example code

import { Audio } from 'expo-av';

let recordOptions = Audio.RECORDING_OPTIONS_PRESET_HIGH_QUALITY;
recordOptions.ios.extension = '.m4a';
recordOptions.ios.outputFormat = Audio.RECORDING_OPTION_IOS_OUTPUT_FORMAT_MPEG4AAC;
recordOptions = JSON.parse(JSON.stringify(recordOptions));

const recordingRef = useRef(null);

useEffect(() => {
  Permissions.getAsync(Permissions.AUDIO_RECORDING).then((status) => {
    if (status !== 'granted') {
      return Permissions.askAsync(Permissions.AUDIO_RECORDING);
    }
    return {};
  }).catch();
}, []);

const startRecord = async () => {
  try {
    await Audio.setAudioModeAsync({
      allowsRecordingIOS: true,
      staysActiveInBackground: false,
      interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
      playsInSilentModeIOS: true,
      shouldDuckAndroid: true,
      interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
      playThroughEarpieceAndroid: true,
    });

    const recording = new Audio.Recording();
    await recording.prepareToRecordAsync(recordOptions);
    await recording.startAsync();
    recordingRef.current = recording;
  } catch (error) {
  }
};

const stopRecord = async () => {
  try {
    await recordingRef.current.stopAndUnloadAsync();
  } catch (error) {
};

I don’t know if this is related to this phenomenon, but durationMillis may be negative.
In particular, it occurs in the second and subsequent recordings.

recording.setOnRecordingStatusUpdate((e) => {
  console.log(e);
  // durationMillis: -6323350
});

This is not reproduced in the iOS simulator.
It is reproduced when using the actual machine.

Tested with iOS12.3.1.

https://github.com/expo/expo/issues/6114

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.