Closed Slooowpoke closed 8 years ago
Hey !
This plugin offers an AudioUtils object that exposes directories in which you can save.
MainBundlePath
CachesDirectoryPath
DocumentDirectoryPath
LibraryDirectoryPath
PicturesDirectoryPath
MusicDirectoryPath
DownloadsDirectoryPath
MainBundlePath
CachesDirectoryPath
DocumentDirectoryPath
LibraryDirectoryPath
This component should be enough if you just want to save the file locally :
import { AudioUtils, AudioRecorder, AudioPlayer } from 'react-native-audio';
const myAudioRecorder = {
record(audioFileName){
const audioPath = AudioUtils.DocumentDirectoryPath+audioFileName;
AudioRecorder.prepareRecordingAtPath(audioPath, {
SampleRate: 22050,
Channels: 1,
AudioQuality: "Low",
AudioEncoding: "aac"
});
AudioRecorder.startRecording();
setTimeout(AudioRecorder.stopRecording, 500);
}
play(audioFileName){
const audioPath = AudioUtils.DocumentDirectoryPath+audioFileName;
// Promise only in android for now.
AudioPlayer.play(audioPath).then(play => {
}).catch((err)=>{
console.warn(err);});
})
}
};
If you want to upload and download voice files then using react-native-fs would be a great idea.
Cheers !
Will this show up when browsing the file system? The files are perfect for playback but I can't seem to find them anywhere?
Thank you.
Fixed the example I forgot to add startRecording.
After recording it creates the file at AudioUtils.DocumentDirectoryPath+audioFileName
Log the variable to check where the file is stored.
Thank you sooooo much! I found them with ease. I struggled with finding the files when browsing using the computer's file browser but when I checked on the phone with a file explorer there it was sitting there. Thanks a ton.
You're welcome :) Cheers !
@RakanNimer, are you sure MainBundlePath is working for Android? https://github.com/jsierles/react-native-audio/blob/9d5e36e31831a2ef1ae7272d4c3141c945dfd89b/android/src/main/java/com/rnim/rn/audio/AudioRecorderManager.java#L63
Less of an issue, more of a question.
The plugin works great. However I am struggling to find where the audio files save to, is it a temporary location for playback? Or do these files get put somewhere special? Playback is working fine but I'm wondering where it is playing from.
Should I be using something like react-native-fs for saving the file?