开发者

Android MP3 MediaPlayer Crashes Some Handsets

I released my first Android app two weeks ago (an MMO called Agent Syndicate) and everything has been working well, except for sounds and music!

Using standard MP3 files created in Sony's Sound Forge Pro 10 at 128kps, I immediately received reports from many users complaining about Force Close issues on a wide variety of handsets, mostly running Android 2.1 and 2.2. I released a new version which has all sounds turned off, and the complaints ceased. I'd really like to have sounds however, so this is far from ideal.

I don't have access to the resources to test the game on anything other than my personal phone and the emulator (where everything works flawlessly), but it's obvious there is a major issue for many players!

Should I not be using MP3s? Is there a universal method that works best for all handsets for just playing simple sound files?

This is what I'm using to start my sound effects:

final MediaPlayer player = MediaPlayer.create(GlobalState.Instance, resId);
player.setOnCompletionListener(new MediaPlayer.OnCompletionListener()
{
    public void onCompletion(MediaPlayer mp)
    {
        mp.release();
    }
});
player.setVolume(0.5f, 0.5f);
player.start();

I originally was calling player.prepare() before player.start(), but kept getting IllegalStateExceptions on some of the sound files. Some of the information out there is very confusing on when e开发者_运维知识库xactly to call these methods, and what the exception means. Removing player.prepare() made it work 100% of the time for me on the emulator and my local dev device.


There should be no problem using the MediaPlayer for music but for sound effect I would use the SoundPool class instead. My guess is you get the IllegalStateExceptions because you are starting the MediaPlayer before the player preperation is completed. Correct way would be to introduce a onPreparedListener for the MediaPlayer and start is from there. Are you making MediaPlayer operation on the main UI thread?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜