02 Nov 2009, 14:06
Generic-user-small

Kevin Graham (5 posts)

I’m having trouble with the Audio project. Of the up, down, left, right, enter, a, s, d, and f audio files, the last two MediaPlayers created throw errors. The LogCat says the following:

PlayerDriver - Command PLAYER PREPARE completed with an error or info PVMFErrResource MediaPlayer - error(1, -17) MediaPlayer - create failed: MediaPlayer - java.io.IOException: Prepare failed.: status=0x1 MediaPlayer - at android.media.MediaPlayer.prepare(Native Method)

Can someone point me to a resource for the error codes? It’s behaving like there is a resource problem. Anyone else have problems like this one?

Thanks, Kevin

03 Nov 2009, 16:21
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

I got that once but couldn’t reproduce it. I’ll try to track it down but I doubt you’ll encounter this in your own programs, especially if you take my advice to use .ogg files instead of .mp3 for short sound effects. .ogg files go through a completely different path in the audio decoder.

06 Nov 2009, 08:00
Generic-user-small

Bill Anderson (4 posts)

I’m seeing the exact same thing. I am running it on an Android 2.0-based Emulator. Perhaps I should target 1.5 and see what happens. I’ll try converting the files to .ogg as well.

–Bill

06 Nov 2009, 08:08
Generic-user-small

Bill Anderson (4 posts)

Converted everything to .ogg and it works fine…

–Bill

18 Nov 2009, 00:00
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

I tracked this problem down and it’s caused by having too many MediaPlayer objects active at once. You wouldn’t think that 8 or 9 would be too many, but apparently it is in Android 2.0 and maybe in 1.6. The maximum number is not documented.

To fix the example, I could do one of the following:

  1. I could use fewer sounds, e.g., just up, down, left, and right, which hopefully wouldn’t run into the limit.
  2. I could put in error checking to test for a null MediaPlayer before playing it. That would get rid of the Force Close but not produce sound for some keys.
  3. I could use .ogg instead of .mp3, because .ogg seems to have a higher limit on the number of players and .ogg files start playing quicker than .mp3 files (good for sound effects).
  4. I could create a new MediaPlayer when the button was pressed and try to make sure it’s cleaned up correctly and that no more than a low number are created if you press several keys.
  5. I could create one MediaPlayer and stop and reuse it when a button is pressed. Anything playing would be truncated so that only one sound would be heard at a time.
  6. I could use SoundPool instead of MediaPlayer.

I don’t want to make the example complicated because that would get in the way of teaching the reader a simple concept that will then be plugged into the Sudoku game. So I’m leaning towards #1 or #5. Opinions are welcome.

01 Dec 2009, 16:16
Logoc_pragsmall

Felix Bearden (1 post)

I like #5. It also may be useful to mention that limit in further versions of the book (referencing the version of Android) so people that like to optimize don’t run into the same problem.

22 Feb 2010, 22:35
Sueprofilepic_pragsmall

Erik Anderson (2 posts)

I would vote for #3 as it doesn’t involve anything other than switching out files. However, who’s to say some limit won’t be encountered with that option? With that in mind, and other possible limitations to be encountered, I vote for #5.

23 Feb 2010, 01:38
Burnette_ed_pragsmall

Ed Burnette (1316 posts)

I decided to go with #5. The latest version of the examples can be found in the 3rd edition samples at http://pragprog.com/titles/eband3/source_code .

  You must be logged in to comment