我有一个应用程序,可以在SD卡上记录和存储音频。它将其记录并保存在正确的位置,但将其保存为android.widget.EditText@random number。我使用EditText来获取文件名。
有谁知道如何让用户输入一些文本并保存文件。我以为我的代码是下面的代码,但没有......
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();
这是我更新的代码:
//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);
答案 0 :(得分:1)
android.widget.EditText@random数字表示您的getInput
是EditText
,因此要获取其文本,您需要调用其getText()方法,如下所示,
String filename = getInput.getText().toString();