2

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);
    }
    }
mira
  • 1,056
  • 3
  • 15
  • 32
  • 1
    "But after touching 10times MediaPlayer stop playing sounds on short time" does it play normally with one touch? – Ahmad Dwaik 'Warlock' Oct 24 '13 at 12:56
  • With one touch ok, when I press more times (quickly or slowly) it is ok. Then after some clicks (approx 10 - not exactly) sound is mutted. Then after sometime (about 10-15 sec) sound play again. – mira Oct 24 '13 at 13:14
  • 1
    For short audio files like we use in games. Sound pool class is the best choice. MediaPlayer is costly in terms of processing. If possible move to SoundPool as early as posible. – Hardik Trivedi Oct 24 '13 at 13:55

1 Answers1

5

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.

mira
  • 1,056
  • 3
  • 15
  • 32