2015-01-08 60 views
0

我使用意图录制声音。在Android上保存录制的声音

但我不知道如何将此声音保存在SD卡中。 我创建一个文件夹“file.mkdirs();”。如何捕获记录并保存到新文件夹(并更改名称)?

如果可能需要保存记录后按下“保存”按钮不中。我认为需要一个变种“记录”,如果他是0没有记录,如果是1是。

保存功能检查声音是否被记录并保存在文件夹中。

public class ObjSuperior extends ActionBarActivity { 


    int peticion = 1; 
    Uri url1; 
    int recorded = 0; 

    private final String ruta_Sonidos = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Gueopic/"; 

    private File file = new File(ruta_Sonidos); 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_obj_superior); 

     //Si no existe crea la carpeta donde se guardaran las fotos 

     file.mkdirs(); 
    } 


    public void grabarSo(View v) { 
     Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION); 
     startActivityForResult(intent, peticion); 
    } 

    public void save(){ 
    //check if file are recorded and save on folder 
    } 

    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (resultCode == RESULT_OK && requestCode == peticion) { 
      url1 = data.getData(); 
     } 
    } 
+1

[中写入一个文件到SD卡(的可能重复http://stackoverflow.com/questions/2455102 /写一个文件到SD卡) –

回答

0

这对我的作品,也许你可以用这个?:

public void recordAudio(String fileName) { 
final MediaRecorder recorder = new MediaRecorder(); 
ContentValues values = new ContentValues(3); 
values.put(MediaStore.MediaColumns.TITLE, fileName); 
recorder.setAudioSource(MediaRecorder.AudioSource.MIC); 
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4); 
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); 
recorder.setOutputFile("/sdcard/sound/" + fileName); 
try { 
    recorder.prepare(); 
} catch (Exception e){ 
    e.printStackTrace(); 
} 

final ProgressDialog mProgressDialog = new ProgressDialog(MyActivity.this); 
mProgressDialog.setTitle(R.string.lbl_recording); 
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); 
mProgressDialog.setButton("Stop recording", new DialogInterface.OnClickListener() { 
public void onClick(DialogInterface dialog, int whichButton) { 
    mProgressDialog.dismiss(); 
    recorder.stop(); 
    recorder.release(); 
    } 
}); 

mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener(){ 
    public void onCancel(DialogInterface p1) { 
     recorder.stop(); 
     recorder.release(); 
    } 
}); 
recorder.start(); 
mProgressDialog.show(); 

}

+0

感谢您的回答,但我需要使用意图打开一个基本的android录音机,没有创建一个录音机。我的代码记录声音,但只需要执行sve功能保存此声音。 – Phyron