audio.waitAudio element

getAudio(id).wait()

or getAudio(id).wait("first")

or getAudio(id).wait(test)

Waits until the audio resource is done playing before evaluating and executing the next commands.

If you call wait("first"), then if the audio has already been played at least once by the time this command is evaluated, the next commands are evaluated and executed right away. If it was never played before, the next commands are only evaluated and executed after the audio has been played.

If you pass a test on an element as an argument, it only evaluates and executes the next commands when the audio finishes playing while the test is successful. If the test is not successful, it will be checked again next time the audio finishes playing.

Example:

newAudio("sentence", "test.mp3")
    .play()
,
newButton("validation", "Validate")
    .print()
    .wait()
,
getAudio("sentence")
    .wait("first")
,
newText("thanks", "Thank you for listening")
    .print()

Starts playing the file test.mp3 and adds a button onto the screen. If the button is clicked before the audio is done playing for the first time, it waits until the end before printing the text Thank you for listening.