4
In my application is recorded sound normally, only I wanted to rename the recorded sound and then store in the device.
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/javacodegeeksRecording.3gpp";
myRecorder = new MediaRecorder();
myRecorder.setAudioSource (MediaRecorder.AudioSource.MIC);
myRecorder.setOutputFormat (MediaRecorder.OutputFormat.THREE_GPP);
myRecorder.setAudioEncoder (MediaRecorder.OutputFormat.AMR_NB);
myRecorder.setOutputFile (outputFile);
public void start(View view){ // começar a gravar
try {
myRecorder.prepare();
myRecorder.start();
//imglisten.setEnabled(false);
} catch (IllegalStateException e) {
// start:it is called before prepare()
// prepare: it is called after start() or before setOutputFormat()
e.printStackTrace();
} catch (IOException e) {
// prepare() fails
e.printStackTrace();
}
}
public void stop(View view){ //para de gravar
try {
myRecorder.stop();
myRecorder.release();
myRecorder = null;
//imglisten.setEnabled(true);
} catch (IllegalStateException e) {
// it is called before start()
e.printStackTrace();
} catch (RuntimeException e) {
// no valid audio/video data has been received
e.printStackTrace();
}
}
I wanted it soon after to stop recording(stop), the save button could rename the recorded and stored sound. How can I do this?
have 2 questions: 1 - How could I do for when the user click save, open a window and then it can rename the file and store on the device? 2 - All recorded files are already being stored on the device ? If not, how could I put to save on the device?
– Gabriel Santana Bonatto
The files are soon stored. If you want to ask the user what file name do this before you start recording. Instead of
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + 
 "/javacodegeeksRecording.3gpp";
open a dialog to ask and pass the answer in the methodmyRecorder.setOutputFile(resposta_do_utilizador)
. In that case it is not necessary to do the name. Research on how to do Dialogs. If you have any difficulty post a new question.– ramaral
I managed to do the dialog, so in this part of the new File codeAudio = new File(newName); it already replaces the old? and also did not understand this part here Boolean success = actualAudio.renameTo(newAudio);
– Gabriel Santana Bonatto
The line that makes the name is
boolean sucesso = actualAudio.renameTo(novoAudio);
– ramaral