Timed Events

Accessors support timed and periodic events with the setTimeout() and setInterval() functions. Each takes a callback function and milliseconds as arguments. Any further arguments will be passed to the callback function.

Here, we'll make a clip player that plays the first seconds of a sound clip.

setup() creates an instance of the ClipPlayer accessor. addInputHandler() starts the player upon a start event and stops it 15000 milliseconds later by sending a value to ClipPlayer's stop input. setInterval() is used to execute a function at a certain time in the future.

Click 'react to inputs'. The clip should play for approximately 15 seconds. The clip may take a few seconds to load and start.

Next, add a parameter to control the clip duration.