I have an app that records and stores the audio on the sdcard. It records and saves it in the right place, but saves it as android.widget.EditText@random number. I was using an EditText to get the filename.
Does anyone know how I can let the user enter some text and save the file as that. I thought I was onto something with the code below, but no...
try {
//Set user input as filename
String filename = getInput.toString();
// set the storage directory to SDcard
File storageDir = new File(Environment.getExternalStorageDirectory(), "audio");
storageDir.mkdir();
Log.d(APP_TAG, "Storage directory set to " + storageDir);
outfile = File.createTempFile(filename, ".3gp", storageDir);
//show filename
System.out.println("File is: "+outfile.getAbsolutePath());
// initiate recorder
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(outfile.getAbsolutePath());
} catch (IOException e) {
Log.w(APP_TAG, "File not accessible ", e);
} catch (IllegalArgumentException e) {
Log.w(APP_TAG, "Illegal argument ", e);
} catch (IllegalStateException e) {
Log.w(APP_TAG, "Illegal state, call reset/restore", e);
}
startRecord();
} else {
stopRecord();
here is my updated code:
//set filename to user input
String filename = getInput.getText().toString()+".3gp";
// show filename
System.out.println("File is: " + filename);
// initiate recorder
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile("/sdcard/audio/"+filename);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
player.setDataSource(filename);