Can't open an existing file in Sdcard in Android Studio
17:47 02 Jun 2015

I have this code in my project to read an audio file:

MainActivity2:

private String getFilename() { 
    String filepath = Environment.getExternalStorageDirectory().getPath();
    File file = new File(filepath, AUDIO_RECORDER_FOLDER);
    if (!file.exists()) {
        file.mkdirs();
    }
    return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + file_exts[currentFormat]);
}

private void startRecording() {
    recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(output_formats[currentFormat]);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile(getFilename());
    Log.i("Tag", getFilename());
    ListeAudio.put(indice,getFilename()); // here is ListeAudio
    path=getFilename();
    recorder.setOnErrorListener(errorListener);
    recorder.setOnInfoListener(infoListener);
    try {
        recorder.prepare();
        recorder.start();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

    

MainActivity:

File AudioFile = new File( MainActivity2Activity.ListeAudio.get(z));
    // ListeAudio return /storage/sdcard0/AudioRecorder/1433288052123.mp4    
    Uri AudioUri = Uri.fromFile(AudioFile);
    vocal = MediaPlayer.create(MainActivity.this,AudioUri);
    vocal.start();

that's doesn't work and in logcat there is an error who says:

Failed to open file '/storage/sdcard0/AudioRecorder/1433288052123.mp4'. (No such file or directory)

And when I search manually this path in the file explorer I found the audio file which I want to play.

I have this in the AndroidManifest:




Please help.

android android-studio record