i am saving some voice recording through mediaplayer:
private void startrecording() {
audiofile = getAudiofile();
if (audiofile != null)
myaudiorecoreder = new MediaRecorder();
myaudiorecoreder.setAudioSource(MediaRecorder.AudioSource.MIC);
myaudiorecoreder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
myaudiorecoreder.setOutputFile(audiofile.getAbsolutePath());
myaudiorecoreder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
try {
myaudiorecoreder.prepare();
setRecordstatus(true);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
myrecordtextview.setText("RECORDING STARTED..SPEAK NOW");
myaudiorecoreder.start();
//
where audiofile will give the sound file.
here is the code for getAudiofile() from which i am getting the file(empty).
//
private File getAudiofile() {
String extState = Environment.getExternalStorageState();
if (extState.equals(Environment.MEDIA_MOUNTED)) {
File mediaStorageDir = new File(
Environment.getExternalStorageDirectory() + "/TAUKY/AUDIO");
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
Log.e("SDCARD", "failed to create directory");
Toast.makeText(getApplicationContext(),
"FAILED TO CREATE DIR", 0).show();
return null;
}
}
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
.format(new Date());
mediaFile = new File(mediaStorageDir.getPath() + File.separator
+ "SOUND_" + timeStamp + ".mp3");
// Toast.makeText(getApplicationContext(), "FILE CREATION DONE",
// 0).show();
} else {
Toast.makeText(getApplicationContext(), "NO SDCARD", 0).show();
}
return mediaFile;
}
now on the next activity how to retrieve from the specific folder of the sdcard i.e /TAUKY/AUDIO
Thanks
Your question is not very clear but if you want to play the file after saving it in the sdcard you can do something like that since you know the path to your file.
I’m not 100% sure since i couldn’t test it but it should be something like that. Hope this helps.