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

android media player library
mediaplayer android
android media player app
android mediaplayer video example
mediaplayer java
android-mediaplayer service example
mediaplayer setvolume
mediaplayer prepareasync

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.

I do not know if this is your issue, but I just found a solution to the problem the described by Tuszy above. I could read the file I was creating from external storage but not from Cache.

The solution is that the read write permissions when writing the file are different.

Please see this excellent explanation in this blog I found.

Android - MediaPlayer, MediaDataSource) transfers a MediaPlayer object in the Idle state to the Initialized state. An IllegalStateException is thrown if setDataSource() is called in any other  Home » Android » Android MediaPlayer throwing “Prepare failed.: status=0x1” on 2.1, works on 2.2 Android MediaPlayer throwing “Prepare failed.: status=0x1” on 2.1, works on 2.2 Posted by: admin February 24, 2018 Leave a comment

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);
}   finally {
    if (fis != null) {
        try {
        } catch (IOException ignore) {


all the resource when the application is in onPause() state. I am trying to play an .opus media file from my android app (targeting 5.0+). The source of this file is the device external storage. The MediaPlayer keeps on throwing a " Prep

I know that I am late here but hopefully this helps somebody else. I worked around this issue by setting up a setOnCompletionListener callback that explicitly releases the MediaPlayer object after the media is done playing.

I can't take credit for this solution, as it was originally posted by Ronny here: How do you detect when a sound file has finished?

But since this is the first answer when I search for Android+Failed Status 0x1 here is my code that solved this problem for me:

 public void playSound(String soundPath){
    MediaPlayer m = new MediaPlayer();

    m.setOnCompletionListener(new OnCompletionListener() {

        public void onCompletion(MediaPlayer mp) {


    try {

        AssetFileDescriptor descriptor = mContext.getAssets().openFd(soundPath);
        m.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(),


        m.setVolume(100f, 100f);

    } catch (Exception e) {
        //Your catch code here.

object you can call some methods to start or stop the music. If you have a look at the state-diagram at the top of the MediaPlayer documentation you can see that stop can only be called after the player is in the Prepared state. The next possibility is that you have already called release() or reset() which will also result in that error.

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.

MediaPlayer; import e) { throw new RuntimeException("Couldn'​t load music"); } } In the constructor, we create and prepare the MediaPlayer  I'm building video player with android media player object. i'm able to hear the audio but the video does not appear on surfaceView. here is my code public class PlayerActivity extends Activity

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());

Java sound must be implemented using the MediaPlayer API. a sound before it plays or issue two simultaneous play commands, the MediaPlayer throws an  Starting with Android 8.0 (API level 26) MediaPlayer can also decrypt Common Encryption Scheme (CENC) and HLS sample-level encrypted media (METHOD=SAMPLE-AES) for the elementary stream types H.264, and AAC. Full-segment encrypted media (METHOD=AES-128) was previously supported.

If anything goes wrong, we throw an unchecked RuntimeException once again. public void dispose() { if (mediaPlayer.isPlaying()) mediaPlayer.stop();  Android MediaPlayer API-compatible media player library with exact seek and DASH support - protyposis/MediaPlayer-Extended. throw new RuntimeException

stopPlayerBtn: if(mediaPlayer != null) { mediaPlayer.stop(); playbackPosition = 0; } break; } } private void playAudio(String url) throws Exception  public void onClick(View v) { mp.start(); We just raised our Series A to enable all developers write better code faster with AI!

stopPlayerBtn: if(mediaPlayer != null) { mediaPlayer.stop(); playbackPosition = 0; } break; } } private void playAudio(String url) throws Exception  MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.sound_file_1); mediaPlayer.start(); // no need to call prepare(); create() does that for you In this case, a "raw" resource is a file that the system does not try to parse in any particular way. However, the content of this resource should not be raw audio.

  • Have you tried that code if you store your file in the SD card and pass its own path?
  • its rather too late, but i guess the constructor of mediaplayer has an overload which takes resourceId
  • I am not working at the same company which had this problem anymore, so I can't say for sure whether the solution would fix this problem. However, I'm going to mark this as the correct answer, as it's the best resource I've seen on this rather obscure bug so far.
  • I don't think that blog exists anymore. Please port the answer here.
  • I managed to dig the blog out of an archiving site. Once you are one the web it is forever.
  • Just a reminder for local files. If MediaPlayer.setDataSource(String path) has prepare error, then this work around does not work either. Since in the background logic of MediaPlayer.setDataSource(String path), it is also using setDataSource(FileDescriptor fd).
  • I also placed them on external storage (Environment.getExternalStorageDirectory()), everything started working.
  • hi, I am facing same issue. My code like this--- MediaPlayer mMediaPlayer=new MediaPlayer(); String PATH_TO_FILE=this.getFilesDir()+"/Organic_chemistry/new_audio.mp3"; mMediaPlayer.setDataSource(PATH_TO_FILE); mMediaPlayer.prepare();
  • Same.. File itself should be updated without hypens,colons and also slash.