I would like input on how to proceed with my code. i have multiple short sound clips (over 100) that will be played based on what the user clicked.
every time an event happens, i check if media player is playing, and stop it if it is. and then used a switch to find the right sound to play. i dont have much experiacne with audio, and i would like some feedback on how my code is ( performance,unforeseen errors, bad habit, etc..), here is my code:
thanks for reading, any feedback is appreciated.
every time an event happens, i check if media player is playing, and stop it if it is. and then used a switch to find the right sound to play. i dont have much experiacne with audio, and i would like some feedback on how my code is ( performance,unforeseen errors, bad habit, etc..), here is my code:
i plan to have up to a maximum of 200 different cases.public void onSoundClick(View v) {
StopIfPlaying();
switch (v.getId()) {
case R.id.sbtn001:
mp = MediaPlayer.create(this.getApplicationContext(), R.raw.ab42);
mp.start();
break;
case R.id.sbtn002:
mp = MediaPlayer.create(this.getApplicationContext(), R.raw.ab52);
mp.start();
break;
}
}
private void StopIfPlaying() {
if(mp != null && mp.isPlaying())
{
mp.stop();
}
}
thanks for reading, any feedback is appreciated.