dimanche 1 février 2015

MediaPlayer: prepare() error for an audio file just created with MediaRecorder

I can't play an audio file recorded by my application. The MediaRecorder works. The files are written in the private storage.


With all the methods I tried I always get the same error while calling the MediaPlayer method prepare():


logcat:



info/warning (1, 9200)
E/MediaPlayer﹕ error (1, 0)
W/System.err﹕
java.io.IOException: Prepare failed.: status=0x1




Relevant pieces of code:



...
mr.stop()


Then in the next lines I try to play that audio file in 3 ways:


(1)



mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
FileInputStream fis = new FileInputStream(new File(path));
mp.setDataSource(fis.getFD());
mp.prepare();
mp.start();
} catch (Exception e) {
e.printStackTrace();
}


(2)



mp = new MediaPlayer();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mp.setDataSource(path);
mp.prepare();
mp.start();
} catch (Exception e) {
e.printStackTrace();
}


(3)



Uri uri = Uri.parse(path);
mp = MediaPlayer.create(this, uri);
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mp.start();
} catch (Exception e) {
e.printStackTrace();
}


Some notes: path should be correct, testing File f = new File(path); f.length() just before playing the files gives me a meaningful value. This is path in the latest run: /data/data/it.giorgini.soundnotes/files/1/temp.aac.


Aucun commentaire:

Enregistrer un commentaire