【发布时间】:2014-11-04 23:42:35
【问题描述】:
嗯,首先我是 android 开发的新手,我正在自学。我按照一些教程制作了一个录音机应用程序。但在这些教程中,将录制的文件保存在路径 /sdcard 中。我希望我的应用程序保存到另一个位置。例如在 /sdcard/Voice 路径中(未创建语音文件夹)。最简单的方法是如何做到的?我搜索了很多,但找不到任何答案。
我的代码(请理解我的母语是西班牙语,所以一些方法是西班牙语)
public class FragmentRecording extends Fragment {
private MediaRecorder recorder;
private String OUTPUT_FILE;
FloatingActionButton stop_fab;
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
View view=inflater.inflate(R.layout.fragment_recording, container,false);
stop_fab=(FloatingActionButton)view.findViewById(R.id.stop_fab_xml);
//SALIDA DEL ARCHIVO
OUTPUT_FILE=Environment.getExternalStorageDirectory()+"/VoiceRecorder.3gpp";
//GENERAMOS UN METODO PARA SABER LIBERAR EL MICROFONO
LiberarMicro();
//Crea el archivo
File outfile=new File(OUTPUT_FILE);
//Si existe lo borra
if(outfile.exists()){
outfile.delete();
}
//Empieza Proceso de Grabacion
try {
StartRecord();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
stop_fab.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
StopRecord();
}
});
return view;}
protected void StopRecord() {
// TODO Auto-generated method stub
if(recorder!=null){
recorder.stop();
}
}
private void StartRecord() throws IllegalStateException, IOException {
// TODO Auto-generated method stub
recorder=new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(OUTPUT_FILE);
recorder.prepare();
recorder.start();
}
private void LiberarMicro() {
// TODO Auto-generated method stub
if(recorder!=null){
recorder.release();
}
}}
【问题讨论】: