Hey I created a Soundboard with 200 Sounds but when I click a lot on the buttons the MediaPlayer stops working although I clean up the MediaPlayer.
Here is the code with only 2 Sounds:
public class MainActivity extends AppCompatActivity{
public MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
//plays sound
public void sound1(View view){
cleanUpMediaPlayer();
mp = MediaPlayer.create(this, R.raw.sound1);
mp.start();
}
public void sound2(View view){
cleanUpMediaPlayer();
mp = MediaPlayer.create(this, R.raw.sound2);
mp.start();
}
public void cleanUpMediaPlayer(){
if(mp != null) {
if(mp.isPlaying()) {
try {
mp.reset();
mp.prepare();
mp.stop();
mp.release();
mp = null;
} catch (Exception e){
e.printStackTrace();
}
}
}
}
}
What is wrong with this Code? And why does my MediaPlayer stops working after approximately 80 clicks.