Please provide the following:
- SDK Version: 37.0.3
- Platforms(Android/iOS/web/all): iOS
Hi all,
In my app, I am trying to save an audio recording made through the phone microphone.
I am testing it in a physical iphone 7 plus.
_recordAudio() and _stopAudio() are executed with an onPress method of two seperate buttons (omitted here)
Here is the relevant code:
this.recording = null
_stopAudio = async () => {
Alert.alert("Note", "You are now STOPPED recording.")
this.setState({isrecording: false})
await this.recording.stopAndUnloadAsync();
const info = await FileSystem.getInfoAsync(this.recording.getURI());
this._playaudio(this.recording.getURI())
const audiofile = await MediaLibrary.createAssetAsync(this.recording.getURI());
MediaLibrary.createAlbumAsync('abc-files', audiofile).then(() => {
}).catch((error) => {
console.log(error);
});
}
_playaudio = async (uril) => {
s = {}
s.uri = uril
const soundObject = new Audio.Sound();
await soundObject.loadAsync(s);
soundObject.playAsync();
}
_recordAudio = async () => {
Alert.alert("Note", "You are now recording.")
const recording = new Audio.Recording();
try {
await Audio.setIsEnabledAsync(true)
await Audio.setAudioModeAsync({playsInSilentModeIOS: true, allowsRecordingIOS: true})
await recording.prepareToRecordAsync()
await recording.startAsync();
this.setState({isrecording: true})
this.recording = recording
// You are now recording!
} catch (error) {
console.log("error at recoding:")
console.log(error)
this.setState({isrecording: false})
}
}
When the _stopAudio() function is executed it is supposed to stop and save the audio to âabc-filesâ but i am getting the error:
[Unhandled promise rejection: Error: This file type is not supported yet]
This error occurs when i am trying to save the file using MediaLibrary (in _stopAudio() ). The file is a â.cafâ file.
Note: _playAudio() works fine and i can hear my recording when it is called from _stopAudio() , so my caf audio file is fine.
The permissions i am asking for is: Permissions.AUDIO_RECORDING and Permissions.CAMERA_ROLL and are being granted before render.
I have checked the variables in this.state at each point and it is as it should be.
This works on Andriod (Pixel 2 and 3)
Any help would be appreciated as i am new to this sort of thing.