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

6 Answers

This is my solution:

MediaPlayer mediaPlayer = new MediaPlayer();
FileInputStream fis = null;
try {
    fis = new FileInputStream(mp3File);
}   finally {
    if (fis != null) {
        try {
        } catch (IOException ignore) {

android media player library

I've been really banging my head against the table trying to get the MediaPlayer class to try to play h.264-encoded videos on Android 2.1. My code is rather simple:

  AssetFileDescriptor fileDescriptor = getResources().openRawResourceFd(R.raw.my_movie);
  introMoviePlayer = new MediaPlayer();
  introMoviePlayer.setDataSource(fileDescriptor.getFileDescriptor(), fileDescriptor.getStartOffset(), fileDescriptor.getDeclaredLength());

This always throws an exception at prepare(), with the text Prepare failed.: status=0x1. I got a bit more info by using MediaPlayer.create() with a URI, which also throws at prepare(), which is actually called by MediaPlayer.create(), with the message Command PLAYER_PREPARE completed with an error or info PVMFErrResourceConfiguration.

The same code works perfectly in Froyo (2.2). The videos themselves play fine in the video player app. Does anyone have perhaps a helpful hint that might help to solve this problem?

Edit: Still no solution -- very frustrating problem indeed. However, I have found that by creating a VideoView and setting the URI for the raw video works. This is very puzzling, as sending the exact same URI through a MediaPlayer class will throw.

If you are using multiple instances of MediaPlayer, make sure that you've executed release() on a resource before attempting to use it in a different instance.

On my opinion i will ask you to check back your location of your media files<< SONG PATH or MOVIE PATH >>. I faced with this exception, i have overcome by correct "SONG PATH"

initilize the fileName, mediaPlayer instance:

private MediaPlayer mp;
private final static String fileName = "ring";

for playing/starting audio file from res/raw directory:

            mp = new MediaPlayer();
            mp.setAudioStreamType(AudioManager.STREAM_RING); //set streaming according to ur needs
            mp.setDataSource(Context, Uri.parse("android.resource://yourAppPackageName/raw/"+fileName));

        } catch (Exception e) 
            System.out.println("Unable to TunePlay: startRingtone(): "+e.toString());

finally stopping the audioFile:

        if (!(mp == null) && mp.isPlaying())
            mp.release(); //its a very good practice
    catch (Exception e)
        System.out.println("Unable to  TunePlay: stopRingtone():"+e.toString());

In my case it was just a filename that it didn't like:
Removed the hyphens and colons, and the exception went away.

To playback a video or audio file located in the raw folder use:

mMediaPlayer = MediaPlayer.create(this, R.raw.a_video_or_audio_file);

no need to call prepare() when using MediaPlayer.create(Context,R.raw.some_resource_file)