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

Viewed 72954

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.

15 Answers

If anyone else gets stuck on this when reading from a remote URL,

my urls were all nonsecure, (i.e. http instead of https)

since I had no access to the server urls (3rd party)

I had to add the following in the android manifest.

<application
    ...
    android:usesCleartextTraffic="true"
    ...
</application>

playing mp3 files instead of wmva fixed it. Apparently that isn't an issue on API 19

Related