我想將錄製的音頻保存到/ storage/emulated/0/AudioRecorder,這是我的代碼:錄製的音頻無法保存在/ storage/emulated/0/AudioRecorder(有時保存的文件出現,有時不出現)
private String getFilename() {
File file = new File(Environment.getExternalStorageDirectory(), "/AudioRecorder");
if (!file.exists()) {
file.mkdirs();
}
createdDate = DateTools.getDate(System.currentTimeMillis(),"dd-MMM-yyyy hh:mm:ss");
nameFile = createdDate + ".mp4";
pathFile = (file.getAbsolutePath() + "/" + nameFile);
return pathFile;
}
private void startRecording() {
if(RadioManager.getInstance().isPlaying()){
RadioManager.getInstance().stopPlayer();
}
Toast.makeText(VoiceNoteActivity.this, "Mulai Rekam", Toast.LENGTH_SHORT).show();
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(output_formats);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilename());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
try {
recorder.prepare();
recorder.start();
isRecord = true;
countDown.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void stopRecording() {
if (null != recorder) {
countDown.cancel();
timer = 0;
seekbar.setProgress(timer);
try{
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
}catch(RuntimeException stopException){
//handle cleanup here
Log.e("Voice Note Activity ","Voice Recording Error : " +stopException.getMessage());
}
isRecord = false;
time.setText("00:00");
enableButtons(false);
}
}
的文件有時會出現在/存儲/模擬/ 0/AudioRecorder,但有時不顯示(更經常地不會出現)。任何人都可以幫忙?
可以給你一些想法如何解決它現在我面臨同樣的問題@Redturbo –