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:
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:
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.
ReplyDeleteshould you set this all up on the mainactivity page regardless of which activity page uses the sounds?
ReplyDeleteIt should be set in the Activity on which sound is to be played.
DeleteThank 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.
DeleteI 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?
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteNot working 😢ðŸ˜
ReplyDeleteHi! Not working. When I execute I have "Raw cannot be resolved or it's not a field"
ReplyDeleteWant help
When I add a son to my project it disappears. If time its 2mn i have 0mn. Why? Thanks.
ReplyDeleteI 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?
ReplyDeleteBecause you aren't allowed to do that by other of Google
DeleteHelp me I am not able to add sound in manager
DeleteHow I can allow this please help
https://play.google.com/store/apps/details?id=com.visionprototype.olchiki&showAllReviews=true
ReplyDeleteWill 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
Constructor SoundPool is depreciated. What now?
ReplyDeleteCan you help me about the soundpool, i want it to be like you click a button where you can choose it as a ringtone
ReplyDeleteThanks
my sound is really short so sketchware crashes when i try to import it pls help
ReplyDeleteHappened to me when I used mp3 but when I converted to wav it worked fine
Delete