| Play Sound () Until Done | |
play sound ( v) until done | |
| Category | Sound |
| Type | Stack |
| Introduced in | 20Jun05 (0.x) |
The Play Sound () Until Done block is a Sound block and a stack block. The block will play the specified sound, pausing its script until the sound has finished playing (unlike the Start Sound () block, which will play the sound without pausing its script).
In the Experimental Viewer, early versions of the Scratch 2.0 alpha, and early versions of Scratch 1.x, the block was called Play Sound () and Wait.
Example Uses
As this block plays a sound and pauses its script until the sound is done, it is mainly used when a sound must be played and the script must be kept from continuing until the sound has finished playing.
Some common uses for the Play Sound () Until Done block:
- Looping a music track, such as for background music
forever play sound (Music v) until done
- Using the block to have delays instead of using the Wait () Seconds block
when I receive [Start speeches v] play sound (Speech1 v) until done play sound (Speech2 v) until done play sound (Speech3 v) until done stop [all v]
Interruption
Although this block plays the sound until done, it can still be interrupted during its running. It is important to note that it will stop running after it finished once. There are some ways for the block to be interrupted and stop playing the sound:
- The Stop All Sounds block will, of course, stop the sound.
- The Stop () block also has the capability of interrupting the play while also ending the script during the sound's running.
- Also, if the sound is within a broadcast or custom block and the script is running, if the procedure is called again, the sound will stop and the script will restart.
- Furthermore, the stop sign stops all sounds, ignoring their progress.
Workaround
- Main article: List of Block Workarounds
This block can be replicated with the following code:
start sound (recording1 v) wait (length of sound in seconds) seconds
This workaround requires knowing the exact length of the sound in seconds.
Things Worth Noting
When a Sound has a Number for its Name
When at least one of the sounds' names is a number and you pass that number to this block, the block's behavior will be different depending on the input's type:
- if the input is a number-type value (e.g a number returned by a
(() + ())), the block will play the sound with that sound number. - otherwise, or if it's a string-type value (e.g a number joined together with a
(join [] [])block), the sound named that number will play.[1]
So, play sound (round (5)) until done will play the fifth sound, but play sound (join [5] []) until done will play the sound that has the name "5".