Posts

Showing posts with the label soundpool

Play/pause button for mediaplayer and soundpool

Image
Sometimes the user is playing your game in an office or in a classroom, he may like to switch off the game sounds. And sometimes he may like to switch off sounds to save battery. So it is important to have to a play/pause button for the sounds in your app. To use a mediaplayer for background sound in Sketchware , in onCreate event use MediaPlayer create, set looping and start blocks. For using soundpool, add a number variable 'sound' . Then use soundpool create max stream count (5) (*if you have five different sounds). Then one by one add the five sounds to the number variable 'sound' using the block soundID...load... And then wherever the sound is to be played, set number variable 'sound' to StreamID SoundPool name play sound ID ... 1+ times . Now, in order to create a play/pause button for both the Mediaplayer and the soundpool together, follow the steps given below. 1. Add an Imageview and two images, one for sound on and other for sound o...

How to use soundpool in Sketchware?

Image
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...