Android IDE (AIDE) Support Forum

How to ad game hit sound

How to ad game hit sound

To sum up:

1- Create a “raw” folder insude the “res” folder of your project and put your sound file inside it, make sure its name is in lowcase.

2- Create these variables:
SoundPool mSP;
int hitSound;
(it might be more practical to use an int[] array to manage multiple sound effects)

3- Instantiate the variables:
mSP = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
hitSound = load(this, R.raw.hitsound, 1);
(assuming the sound file is named “hitsound”)

4- Play the sound effect
mSP.play(hitSound, 1, 1, 1, 0, 1);

5- Check the SoundPool documentation because there are several limitations and guidances you need to be aware of. (f.e.: for larger sounds, such as background music, you will need to use the MediaPlayer class instead)