I'm develop some app with recording voice function and I just want to save it on my external storage, now I know how to save it without a folder but I want that my app creates unique folder for the files I recorded
my code:
public class MainActivity extends Activity {
MediaRecorder recorder = null;
MediaPlayer player = null;
public static String OUTPUT_FILE;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
OUTPUT_FILE = Environment.getExternalStorageDirectory()+"audiorecorder.acc";
}
public void record(View v) {
try {
beginRecording();
} catch (IllegalStateException | IOException e) {
e.printStackTrace();
}
}
public void stop(View v) {
stopRecording();
}
public void play(View v) {
try {
beginPlay();
} catch (IllegalArgumentException | SecurityException
| IllegalStateException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void stopPlayback(View v) {
StopPlay();
}
private void beginRecording() throws IllegalStateException, IOException {
dictchMediaRecorder();
File file = new File(OUTPUT_FILE);
if(file.exists()){
file.delete();
}
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB);
recorder.setAudioEncodingBitRate(9600);
recorder.setAudioSamplingRate(44100);
recorder.setOutputFile(OUTPUT_FILE);
recorder.prepare();
recorder.start();
}
private void beginPlay() throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {
ditchMediaPlayer();
player = new MediaPlayer();
player.setDataSource(OUTPUT_FILE);
player.prepare();
player.start();
}
I'm only added this lines and it's work perfect:
File dir_image;
public static String OUTPUT_FILE;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dir_image = new File(Environment.getExternalStorageDirectory()+File.separator+"folderName");
dir_image.mkdirs();
OUTPUT_FILE = dir_image.getPath()+"/acapella.wav";