我尝试有意地调用默认录音机并将路径发送到录音机,而不是在sdcard的路径中保存语音。我使用以下代码:
File audioFile = new File(Environment.getExternalStorageDirectory().getPath() + "/nabege" + File.separator + "audio"
+ File.separator + System.currentTimeMillis() + ".amr");
Uri audioUri = Uri.fromFile(audioFile);
record_audio_Intent.putExtra(MediaStore.EXTRA_OUTPUT, audioUri);
startActivityForResult(record_audio_Intent, 0);
此应用将语音保存在默认路径中。此路径(nabege / audio)已在sdcard中创建并存在。请帮助
最佳答案
通过意图进行录音始终会将录制的文件保存到sdcard的根目录(或默认路径)。另外,某些型号的手机可能不支持此意图。
如果要将录制的文件保存到自定义路径,则必须直接使用MediaRecorder。
像这样:
MediaRecorder recorder = null;
private void startRecording(File file) {
if (recorder != null) {
recorder.release();
}
recorder = new MediaRecorder();
recorder.setAudioSource(AudioSource.MIC);
recorder.setOutputFormat(OutputFormat.THREE_GPP);
recorder.setAudioEncoder(AudioEncoder.AMR_WB);
recorder.setOutputFile(file.getAbsolutePath());
try {
recorder.prepare();
recorder.start();
} catch (IOException e) {
Log.e("giftlist", "io problems while preparing [" +
file.getAbsolutePath() + "]: " + e.getMessage());
}
}
关于android - 有意调用录音机并将语音保存在SD卡中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32432058/