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.

 
x
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

Accessor class: tutorial/TimedClipPlayer.

Modules required: util