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.
- Record with our app. Success.
- For example, play music with Spotify or AppleMusic.
- 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) {
};