Search code examples
androidmedia-player

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


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());
  introMoviePlayer.prepare();

This always throws an exception at prepare(), with the text java.io.IOException: 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.


Solution

  • 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.

    http://blog.weston-fl.com/android-mediaplayer-prepare-throws-status0x1-error1-2147483648/

    enter image description here

    enter image description here