问题
Having small game to play short sound after onclick ImageButton. But after touching 10times MediaPlayer stop playing sounds on short time. After sometime it play sound again. When I look to LogCat console it show error: E/MediaPlayer(19584): error (1, -2147483648)
.
Please can you show me the way to find sollution to solve this problem ? Why MediaPlayer gives me error ?
I use this part of code to play Sound:
public void playAudio () {
try {
mediaPlayer = MediaPlayer.create(getBaseContext(), R.raw.trefa);
mediaPlayer.setLooping(false);
mediaPlayer.start();
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
}
});
} catch (Exception e) {
Log.e("beep", "error: " + e.getMessage(), e);
}
}
回答1:
The sollution for me is really to use SoundPool (not MediaPlayer). I have replaced my MediaPlayer with SoundPool from this tutorial: http://www.edumobile.org/android/android-programming-tutorials/sound-pool-example-in-android-development and everything is ok.
来源:https://stackoverflow.com/questions/19566450/android-mediaplayer-stops-playing-after-some-time