Problem looping a sound

I’m trying to loop a sound when button is pressed, and having some trouble. Shouldn’t this block play the sound 5 times?

loop

This just plays the sound once though.

Any tips to get a sound to loop in Thunkable X?

Or to get the old Player object, that had a loop property?

Edit: I think the issue with the method in my screenshot aove is that it’s executing the Sound1.Play action 5 times instantly without waiting for the sound to finish playing… In the method below for example the text of “now playing” instantly becomes “10”, instead of iterating from 1 to 10 with each loop.

loop2

So far the best solution I’ve come up with is something like the below. This successfully loops the sound 4 times, and I could keep adding blocks to simulate an infinite loop, but that’s obviously uggggllllyyyyy and shouldn’t be necessary.

Yes.
Except it will be playing it 5 times at the same time.

The reason for this is that the sound play is just a request to the OS to activate whatever is required to decode the mp3 and play it. And the reason why the system does not wait until it is finished is because you need to be able to run sound simultaneously, like when a game will have to feature background music and sound effects.

The best way to run multiple times is probably to use a start signal, with a delay to avoid checking too often, something like:

image

(Note: this is UNTESTED. It is possible that I am way off with this and that it does not work; it is 4 AM here and I should be in bed already. But it seems like it should.)

The way this works is that the repeat loop sets a logical playing as a marker of a current activity. Asynchronously, the logic will get to the loop of waiting 1 second until the end of the play resets the value of the logical that will break-off out of the while loop, which will then fall back to the repeat loop.

If this does not work, leave a note to this effect and I will check it out when I get up.
If it works, mark it as solved.

1 Like