I need help with Audio recording


#1

Hello guys… Hope you’re doing great? I’m trying to record an audio on my app but I keep getting this error: _expo.Audio.setAudioModeAsync is not a function… can anyone tell me what am I doing wrong?
here’s the code:

_recordAudio = async () => {
    Audio.setIsEnabledAsync(true);
    Audio.setAudioModeAsync({
      allowsRecordingIOS: true,
      interruptionModeIOS: Audio.INTERRUPTION_MODE_IOS_DO_NOT_MIX,
      playsInSilentLockedModeIOS: false,
      shouldDuckAndroid: true,
      interruptionModeAndroid: Audio.INTERRUPTION_MODE_ANDROID_DO_NOT_MIX,
    });
    this._askForAudioPermission();
    this._onRecordPressed();
  }

_askForAudioPermission = async () => {
const response = await Permissions.askAsync(Permissions.AUDIO_RECORDING);
this.setState({
haveRecordingPermissions: response.status === ‘granted’,
});
console.log(“PERMISSION:”, JSON.stringify(this.state.haveRecordingPermissions));
};

_onRecordPressed = () => {
if (this.state.isRecording) {
this._stopRecordingAndEnablePlayback();
} else {
this._stopPlaybackAndBeginRecording();
}
};

async _stopPlaybackAndBeginRecording() {
this.setState({
isLoading: true,
});
if (this.sound !== null) {
await this.sound.unloadAsync();
this.sound.setCallback(null);
this.sound = null;
}
if (this.recording !== null) {
this.recording.setCallback(null);
this.recording = null;
}

const recording = new Audio.Recording();
await recording.prepareToRecordAsync();
recording.setCallback(this._updateScreenForRecordingStatus);
this.recording = recording;
await this.recording.startAsync(); // Will call callback to update the screen.
this.setState({
  isLoading: false,
});

}


#2

hey @ahmad - can you reproduce your example on https://snack.expo.io/? it makes it a lot easier for us to determine the source of the problem


#3

@notbrent all right just a second…


#5

hello @notbrent this is kind of the example that I’m trying to do: https://snack.expo.io/SJEQ_uvbb, although here I’m not getting the error I am getting in the project but still I’m not able to make it to record and play the recording back.


#6

hello again @notbrent can you tell brent that I really need his help on this? :sweat_smile: I downloaded the audio-recording-example-app from github to try and play around with it so that maybe I can realise what I am doing wrong… but after I ran it and tried to record I got an error saying that audio is not enabled although it is enabled… I checked from the settings and also I logged the response of the permission and it returned an object with status: granted and expires: never… I can’t seem to figure out the problem, and when I open exp.host/@community/record it works just fine. I’ve been at this for a couple of days… I would really appreciate if you can figure out what could be going on… thanks in advance… I’ll leave this here just try to give it a look when you are free… have a good day =)…


#7

problem solved… I had been using the older idk version of expo… I updated the idk version and now it works fine.