如何解决我如何处理来自 MediaRecorder 的 setOutputFile 以获取 Uri android 10
我需要录制语音这个函数 setOutputFile() 需要一个输出文件的路径并且需要处理我的 Uri 不是路径的作用域存储我该怎么办?
<select>
<option value="Option1">Option1</option>
<option value="Option2">Option2</option>
<option value="Option3">Option3</option>
<option value="Option4">Option4</option>
</select>
这一行应该改变
public void startRecording() {
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(output_formats[currentFormat]);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recordingName = getFilename();
recorder.setOutputFile(recordingName);
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
try {
recorder.prepare();
recorder.start();
handler.post(updateVisualizer);
} catch (IllegalStateException | IOException e) {
e.printStackTrace();
}
}
解决方法
我为我的应用使用了公共文件夹 像这个例子 https://github.com/CWMChapman/Audio_Memos
public void startRecording(Button b) {
// state = mounted or unmounted
String state = Environment.getExternalStorageState();
Log.d(TAG,state);
Context ctx = this.getApplicationContext();
File audioDir = new File(ctx.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS),"AudioMemos");
audioDir.mkdirs();
String audioDirPath = audioDir.getAbsolutePath();
Log.d(TAG,"Recording file location: " + audioDirPath);
Date currentTime = Calendar.getInstance().getTime(); // current time
String curTimeStr = currentTime.toString().replace(" ","_");
File recordingFile = new File(audioDirPath + "/" + curTimeStr + ".m4a");
Log.d(TAG,"Created file: " + recordingFile.getName());
// try {
// } catch (IOException e) {
// Log.e(TAG,"external storage access error");
// return;
// }
mr = new MediaRecorder();
mr.setAudioSource(MediaRecorder.AudioSource.MIC);
mr.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mr.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mr.setOutputFile(recordingFile.getAbsolutePath());
try {
mr.prepare();
} catch (IOException e) {
Log.e(TAG,"prepare() failed");
}
mr.start();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。