Android MediaPlayer throwing “Prepare failed.: status=0x1” on 2.1, works on 2.2

This is my solution:

MediaPlayer mediaPlayer = new MediaPlayer();
FileInputStream fis = null;
try {
    File directory = new File("android.resource://com.example.myapp/raw/");
    fis = new FileInputStream(directory);
    mediaPlayer.setDataSource(fis.getFD());
    mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
    mediaPlayer.prepare();
}   finally {
    if (fis != null) {
        try {
            fis.close();
        } catch (IOException ignore) {
        }
    }

}

Leave a Comment