-
Notifications
You must be signed in to change notification settings - Fork 0
Play sounds
In this tutorial, we are going to play sounds, multiple sounds in the same time.
Do as in Hello World tutorial except that you change the names: playSounds
, playSounds.html
, playSounds.fg
.
Copy the files ducks.mp3
, birds.mp3
, barking.mp3
into the directory playSounds
.
Write these lines into playSounds.fg
:
parallel ||
playSoundFile('ducks.mp3')
||
playSoundFile('birds.mp3')
||
playSoundFile('barking.mp3')
displayNewMessage('The End')
This block (that I called 'parallel
construct'):
parallel ||
block1
||
block2
||
block3
executes "block1", "block2" and "block3" in parallel (just logical parallelism). Beware that it finished only when all the three blocks are finished.
So when you load playSounds.html
, here is the timeline:
If you change a little the program (add exitAfter 2 finished
just after the parallel
word):
parallel exitAfter 2 finished ||
playSoundFile('ducks.mp3')
||
playSoundFile('birds.mp3')
||
playSoundFile('barking.mp3')
displayNewMessage('The End')
when the two blocks that finished first (playSoundFile('barking.mp3')
and playSoundFile('ducks.mp3')
) are finished,
all the remaining blocks (in this case, just playSoundFile('birds.mp3')
) are discontinued and the parallel
construct finishes.
So that the 'The End' message is displayed. Here is the timeline:
If you change again a little the program (put exitWith branch 3
just after the parallel
word):
parallel exitWith branch 3 ||
playSoundFile('ducks.mp3')
||
playSoundFile('birds.mp3')
||
playSoundFile('barking.mp3')
displayNewMessage('The End')
when the third (in order of writing) block (playSoundFile('barking.mp3')
) is finished,
all the remaining blocks (in this case, playSoundFile('ducks.mp3')
and playSoundFile('birds.mp3')
) are discontinued and the parallel
construct finishes.
So that the 'The End' message is displayed. Here is the timeline:
FuncSug Documentation