Mediaplayer error (-19,0) after repeated plays Mediaplayer error (-19,0) after repeated plays android android

Mediaplayer error (-19,0) after repeated plays


I was getting the same problem, I solved it by adding the following code to release the player:

mp1 = MediaPlayer.create(sound.this, R.raw.pan1);mp1.start();mp1.setOnCompletionListener(new OnCompletionListener() {    public void onCompletion(MediaPlayer mp) {        mp.release();    };});


I think you are not releasing the mediaplayers you are using to play the sound..You need to release() the media players otherwise the resources are not released , and you soon get out of memory (since you allocate them again next time). so,I think you can play twice or even thrice... but not many times without releasing the resources


MediaPlayer is not a good option when you are playing small sound effects as the user can click on multiple buttons very soon and you will have to create a MP object for all of them which doesnt happen synchronously. That is why you are not hearing sounds for every click. Go for the SoundPool Class which allows you to keep smaller sounds loaded in memory and you can play them any time you want without any lag which you would feel in a mediaplayer. http://developer.android.com/reference/android/media/SoundPool.html Here is a nice tutorial : http://www.anddev.org/using_soundpool_instead_of_mediaplayer-t3115.html