androidavaudiofile

can't find audio file after recording


i created a voice recorder in android studio, but i cant find the recorded file on my phone. normally am meant to attach it to an email that will be sent, but i cant find it on my phone for me to add it as an attachment.This is my code written below

   private String outputFile = null;

   private MediaRecorder mRecorder;

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


    outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording.3gpp";
    }




     public void startRecording() throws Exception {



    if(mRecorder!=null){
        mRecorder.release();
    }

    File fileOut = new File(outputFile);

    if(fileOut!=null){
        fileOut.delete();
    }


    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mRecorder.setOutputFile(outputFile);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);


        mRecorder.prepare();

    mRecorder.start();
}





public void stopRecording() {

    if(mRecorder != null) {
        mRecorder.stop();
        mRecorder.release();
    }
}

public void record(){



    new CountDownTimer(10000, 10000) { // 5000 = 5 sec

        public void onTick(long millisUntilFinished) {
            try {
                startRecording();
            } catch (Exception e) {
                e.printStackTrace();
            }
            Toast.makeText(HomeActivity.this, R.string.record_audio, Toast.LENGTH_LONG).show();
        }

        public void onFinish() {
            stopRecording();
            mProgressDialog.dismiss();
            Toast.makeText(HomeActivity.this, R.string.record_saved, Toast.LENGTH_LONG).show();
        }
    }.start();


}

Solution

  • It´s possible that your storage is not mounted. I faced especially on CyanogenMod systems that the sotrages are not mounted by default. Just be sure the storage is mounted by simply calling:

        boolean isMountend = Environment.getExternalStorageState().
    equals(android.os.Environment.MEDIA_MOUNT‌​ED);