How to use soundpool in Sketchware?

The soundpool component is used to play sounds of smaller duration in android apps and a single soundpool component can be used to play multiple sounds.

Now suppose you have three sounds which you want to use in a game at different instances. To use the sounds follow the steps given below.

1. Open the Sketchware project in which you want to use the sounds. Go to sound manager and add the three sounds which you want to use.

2. Now add a soundpool component (named 'sounds' in the image below) in the Logic section of your app.

3. After this go to onCreate event and add a number variable (named sound in the image below).

4. Then in onCreate event, first use the block: SoundPool (name) create max stream count.... Since here three sounds are being used set max stream count to 3.

After that use SoundID:SoundPool (name) load (sound name) and set the number variable to load the three sounds one by one, as shown in the image below.
This will set the SoundID of the three sounds to 1, 2 and 3, depending on the sequence in which they are loaded to the number variable.

5. Now at any time in your app whenever you want to play the sound use the following block:
Set (variable name) to StreamID: SoundPool (name) play sound ID (ID of sound; 1, 2 or 3) 1+ (write 1 less than number of times sound is to be played) times

The Sound ID is set to the sequence in which the sounds were loaded to the variable. So, if you want to play the second sound write sound ID as 2.

1+ __ times determines the number of times the sound will repeat. If it is left blank, the sound will play only once.

The images below shows how to use it.




Watch the video below for better understanding: