Problem looping a sound

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.

3 Likes