Vicky
Vicky

Reputation: 293

how to save multiple record voice in sdcard in android?

i know how to record voice as following code

String path = android.os.Environment.getExternalStorageDirectory()+"/Record/test.3gp";



boolean exists = (new File(android.os.Environment.getExternalStorageDirectory()+"/Record/")).exists();

                if(!exists)
                {
                    newFile(android.os.Environment.getExternalStorageDirectory()+"/Record/").mkdirs();

                }



MediaRecorder recorder = new MediaRecorder();       


recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

                         recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

                recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

                recorder.setOutputFile(path);
                try {
                    recorder.prepare();
                    recorder.start();
                } catch (IllegalStateException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

In this code i give output path in "recorder.setOutputFile(path);" it's work fine but my problem is if i record again it will overwrite the same path, so pls help me how to save mulitiple voice in same path in sdcard pls help me

Upvotes: 0

Views: 1443

Answers (1)

Sufian Latif
Sufian Latif

Reputation: 13356

The file is overwritten because the MediaRecorder object gets the same output path every time. You'll need to provide distinct names for output file each time.

A good way can be using the date/time of the day in the filename.

A trivial example can be:

String path = android.os.Environment.getExternalStorageDirectory()
    + "/Record/test_" + System.currentTimeMillis() + ".3gp";

Upvotes: 3

Related Questions