I am trying to record audio in my Piano app in android studio using MediaRecorder. After searching for answers on how to save the file as getExternalPublicDirectory is deprecated so i used context.getExternalFilesDir(null).getAbsolutePath(); . Now when i run the app and hit the record button , i get this error java.io.FileNotFoundException: open failed: EISDIR (Is a directory) in the line mediaRecorder.prepare(); .. Please Help!!
private void startRecording() throws IOException {
try {
String path = context.getExternalFilesDir(null).getAbsolutePath();
audioFile = new File(path);
} catch (Exception e) {
Log.e("Error Tag", "external storage access error " + e.getMessage());
return;
}
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setOutputFile(audioFile.getAbsolutePath());
mediaRecorder.prepare();
mediaRecorder.start();