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:

Comments

  1. Sound logic is added from the first to third page, but the fourth or upper page sound logic is added, but after the save out, they are deleted and not received. Please help someone.

    ReplyDelete
  2. should you set this all up on the mainactivity page regardless of which activity page uses the sounds?

    ReplyDelete
    Replies
    1. It should be set in the Activity on which sound is to be played.

      Delete
    2. Thank you, both for your response and for this great blog. I would have quit using Sketchware by now if wasn't for this extremely helpful blog.

      Delete
  3. I noticed that if I play the same sound with soundpool, it doesn't have as as much loudness as if I play it with mediaplayer. Does anyone have idea why is that and what could I do do against it?

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Hi! Not working. When I execute I have "Raw cannot be resolved or it's not a field"
    Want help

    ReplyDelete
  7. When I add a son to my project it disappears. If time its 2mn i have 0mn. Why? Thanks.

    ReplyDelete

Post a Comment

Popular posts from this blog

A Flash Light App in Sketchware

Create Music Player app in Sketchware

In Sketchware: How to create a calculator for any simple formula?

Simple car racing android game in Sketchware

Firebase auth in Sketchware for Login Activity