I just want my app to play a sound three times when a button is pressed
. I think i have to create a do while loop but it doesnt seem straightforward.
Use the Player component, which has a completion event.
Init a global variable to count how many times the sound has played.
In the completion event, add 1 to the counter, and check if it's past 3.
If it's short of 3, play it again, Sam.
Here are the blocks with some short sounds as an example... but you will need to carry the sound of your choice -in the Designer, in 'upload file'- and select it in set Player1.source
Try the operation with other sounds present opening this list ↑ ↑ ↑ in Companion
If you need to repeat more than 3 times change the value of the
Global Variable
'Repeat Times'
Also follows the *.aia with the programming ready, to be downloaded to your computer and imported in AI2 as a 'New project'
Play_n_Times.aia (116.7 KB)
Lito
@>-->---
I don't know. If this was basic or 'c' you could just call player1 three times as I have done. See attached photo.
But, AppInventor is not C. Most operations are executed asynchronously. Therefore you have to add the when-Player1-completed block and catch the completion of each play step. When you do more AppInventor projects, you will see the great power of this.