作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 MediaRecorder
在 android studio 的 Piano 应用程序中录制音频。在搜索有关如何将文件保存为 getExternalPublicDirectory
已弃用的答案后,我使用了 context.getExternalFilesDir(null).getAbsolutePath();
。现在,当我运行该应用程序并点击录制按钮时,我在 mediaRecorder.prepare(); 行中收到此错误
.. 请帮忙!! java.io.FileNotFoundException: open failed: EISDIR (Is a directory)
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();
最佳答案
获取 java.io.FileNotFoundException: open failed: EISDIR (Is a directory)
是预期的,因为您提供给 setOutputFile()
的路径指向 < strong>到一个目录而不是一个文件来保存记录的数据。
documentation很清楚,
Sets the path of the output file to be produced.
尝试修复你的路径,
String dirPath = context.getExternalFilesDir(null).getAbsolutePath();
String filePath = direPath + "/recording";
audioFile = new File(filePath);
关于java.io.FileNotFoundException : open failed: EISDIR (Is a directory) 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62101194/
我是一名优秀的程序员,十分优秀!