0

I want to save a recording made in the first activity and then play back the recording in the second activity in my Android App. I think I have everything but I cant seem to find a way to save in the first activity and then be able to access it in the second activity.

Right now, the application crashes because it cant find the file. I will include parts of the first and second activity for review.

This is from the first Activity where the file path is set

 try{
    Log.i(log_tag,"Setting the recorder");
    speaker_recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    speaker_recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    speaker_recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        speaker_recorder.setOutputFile(getFilesDir().getAbsolutePath() + "/audio_test.3gp");

    } catch(Exception e){
        Log.e(log_tag,"Recording Settings Failed");
        createTempFile("Status.txt", "COMPLETED-RECORDER FAILED");
    }
    //Prepare the Recorder
    try{
        Log.i(log_tag,"Preparing the Recorder");
        speaker_recorder.prepare();
    } catch(Exception e){
        Log.e(log_tag,"Recording failed");
        createTempFile("Status.txt", "COMPLETED-RECORDER FAILED");
        exit_function();
    }

This is from the Second Activity where the file is played back

    private void playSound(boolean speakers) {
        mContext = getApplicationContext();
        mFile = "files" + "/audio_test.3gp";
        audioManager.setSpeakerphoneOn(true);
        try {
            mp.setDataSource(mFile);
        } catch (IOException e) {
            e.printStackTrace();
CroMagnon
  • 1,218
  • 7
  • 20
  • 32
Toby
  • 141
  • 3
  • 12

1 Answers1

0

In your first activity, you have:

getFilesDir().getAbsolutePath() + "/audio_test.3gp"

In your second activity, you have:

"files" + "/audio_test.3gp";

These are not the same. Furthermore, the second one is incorrect. Change the second activity to use the same logic to derive the path as you used in the first activity.

(or, better yet, use new File(getFilesDir(), "audio_test.3gp") in both places, rather than use string concatenation)

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491