When I use mediaplayer on click button, after several clicks the sound disappears. When I use soundpool, the time is too short to play the effect sound. Can anybody please help me with this?

1 Answers

Community On Best Solutions

As I understood your audio is 20 s. So you can use this code on your button click:

if (mediaPlayer != null){
    mediaPlayer = null;
mediaPlayer = MediaPlayer.create(this, R.raw.audio_file);

The first if statement is to take care that it will keep playing how much ever you clicked the button.