• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Playing sounds effiecently.

haxxo

Lurker
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:
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();
}
}
i plan to have up to a maximum of 200 different cases.

thanks for reading, any feedback is appreciated.
 
Back
Top Bottom