我在 android studio 中创建了一个录音机,但我在手机上找不到录制的文件。通常我打算将其附加到将要发送的电子邮件中,但我无法在手机上找到它以将其添加为附件。这是我写在下面的代码
private String outputFile = null;
private MediaRecorder mRecorder;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording.3gpp";
}
public void startRecording() throws Exception {
if(mRecorder!=null){
mRecorder.release();
}
File fileOut = new File(outputFile);
if(fileOut!=null){
fileOut.delete();
}
mRecorder = new MediaRecorder();
mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mRecorder.setOutputFile(outputFile);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mRecorder.prepare();
mRecorder.start();
}
public void stopRecording() {
if(mRecorder != null) {
mRecorder.stop();
mRecorder.release();
}
}
public void record(){
new CountDownTimer(10000, 10000) { // 5000 = 5 sec
public void onTick(long millisUntilFinished) {
try {
startRecording();
} catch (Exception e) {
e.printStackTrace();
}
Toast.makeText(HomeActivity.this, R.string.record_audio, Toast.LENGTH_LONG).show();
}
public void onFinish() {
stopRecording();
mProgressDialog.dismiss();
Toast.makeText(HomeActivity.this, R.string.record_saved, Toast.LENGTH_LONG).show();
}
}.start();
}