Here is a simple piano app and it works but there is a problem. After about 20 clicks (sometimes it is exactly 28 clicks) even I click the buttons it doesn\'t play any sound
Looks like you're creating a new MediaPlayer instance to play each sound. You should either reuse them or clean them up.
From the documentation of the MediaPlayer.create() method:
Convenience method to create a MediaPlayer for a given resource id. On success, prepare() will already have been called and must not be called again.
When done with the MediaPlayer, you should call release(), to free the resources. If not released, too many MediaPlayer instances will result in an exception.
simple way is to add onComplationListener
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer p1) {
p1.release();
}
});