Video
Load a video with multiple formats and toggle between playing and paused with a button press.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
let playing = false;
let fingers;
let button;
function setup() {
noCanvas();
// specify multiple formats for different browsers
fingers = createVideo(['assets/fingers.mov', 'assets/fingers.webm']);
button = createButton('play');
button.mousePressed(toggleVid); // attach button listener
}
// plays or pauses the video depending on current state
function toggleVid() {
if (playing) {
fingers.pause();
button.html('play');
} else {
fingers.loop();
button.html('pause');
}
playing = !playing;
}