i'm trying to save the recorded audio files in a folder that i wanted it to be rather then the default folder. but somehow i failed to do so.
my code:
Intent recordIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
Uri mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "/Record/sound_"+ String.valueOf(System.currentTimeMillis()) + ".amr"));
recordIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
startActivityForResult(recordIntent, RESULT_OK);
it did calls the voice recorder app. and also when i press the stop button, it return to my app and have a toast appeared saying its saved. but, rather then saving in my Record folder, it save in the default folder.
i realized that there is error msg in the logcat :
01-29 01:34:23.900: E/ActivityThread(10824): Activity com.sec.android.app.voicerecorder.VoiceRecorderMainActivity has leaked ServiceConnection com.sec.android.app.voicerecorder.util.VRUtil$ServiceBinder@405ce7c8 that was originally bound here
i'm not sure what went wrong as the code works when i call the camera app.
Do in this way, Record with MediaRecorder:
To start Recording:
public void startRecording()
{
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(getFilename());
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
try
{
recorder.prepare();
recorder.start();
}
catch (IllegalStateException e)
{
e.printStackTrace();
} catch (IOException e)
{
e.printStackTrace();
}
}
To Stop:
private void stopRecording()
{
if(null != recorder)
{
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
}
For Selected Folder:
private String getFilename()
{
String filepath = Environment.getExternalStorageDirectory().getPath();
File file = new File(filepath,AUDIO_RECORDER_FOLDER);
if(!file.exists()){
file.mkdirs();
}
return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".mp3");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With