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
  8. I can't add Soundfiles to the spundmanager at all. I have tried many different formats, but the file is just not showing up, any idea why?

    ReplyDelete
    Replies
    1. Because you aren't allowed to do that by other of Google

      Delete
    2. Help me I am not able to add sound in manager
      How I can allow this please help

      Delete
  9. https://play.google.com/store/apps/details?id=com.visionprototype.olchiki&showAllReviews=true

    Will you please check the above app? I have used 30 sounds in the alphabet screen in 6 rows with six different sound pool components. In every rows 5 text views inserted pressing which the play button is assigned with a new sound file. So there are 6 play button in the page. The problem is that some time the it stops playing any sound. The app is created in Sketchware. Hope you can help. You can contact me at www.facebook.com/cFakhar

    ReplyDelete
  10. Constructor SoundPool is depreciated. What now?

    ReplyDelete
  11. Can you help me about the soundpool, i want it to be like you click a button where you can choose it as a ringtone
    Thanks

    ReplyDelete
  12. my sound is really short so sketchware crashes when i try to import it pls help

    ReplyDelete
    Replies
    1. Happened to me when I used mp3 but when I converted to wav it worked fine

      Delete

Post a Comment

Popular posts from this blog

Simple car racing android game in Sketchware

Enable Fullscreen for Youtube videos in WebView

Creating a Drawing View in Sketchware

How to enable upload from webview in Sketchware?

List of Calendar Format symbols valid in Sketchware