xxxxxxxxxx
95
let vid = 0;
var videos = [];
function preload() {
defaultphase = createVideo("Icarus_Phase0.mp4");
defaultphase.hide();
videos.push(defaultphase);
phase1 = createVideo("Icarus_Phase1.mp4");
phase1.hide();
videos.push(phase1);
// phase1 is both a transition phase and looping phase
// push twice to match other videos
videos.push(phase1);
transition2 = createVideo("Icarus_Phase1to2.mp4");
transition2.hide();
videos.push(transition2);
phase2 = createVideo("Icarus_Phase2.mp4");
phase2.hide();
videos.push(phase2);
transition3 = createVideo("Icarus_Phase2to3.mp4");
transition3.hide();
videos.push(transition3);
phase3 = createVideo("Icarus_Phase3.mp4");
phase3.hide();
videos.push(phase3);
transition4 = createVideo("Icarus_Phase3to4.mp4");
transition4.hide();
videos.push(transition4);
phase4 = createVideo("Icarus_Phase4.mp4");
phase4.hide();
videos.push(phase4);
transition5 = createVideo("Icarus_Phase4to5.mp4");
transition5.hide();
videos.push(transition5);
phase5 = createVideo("Icarus_Phase5.mp4");
phase5.hide();
videos.push(phase5);
}
function setup() {
createCanvas(0, 0);
videos[0].show();
videos[0].size(1080, 1920);
videos[0].loop();
}
function keyPressed() {
if (keyCode === RIGHT_ARROW) {
vid++;
}
if (keyCode === LEFT_ARROW) {
vid--;
}
vid = Math.min(Math.max(vid, 0), 5); //clamp to 0-5
console.log(vid);
handleVideoPlay(vid);
}
async function handleVideoPlay(input) {
videos.forEach(function (v) {
v.hide();
});
if (input === 0) {
videos[0].show();
videos[0].loop();
} else {
videoIndex = input * 2;
transitionIndex = videoIndex - 1;
videos[transitionIndex].show();
videos[transitionIndex].play();
await sleep(4000);
videos[transitionIndex].hide();
videos[videoIndex].show();
videos[videoIndex].loop();
}
}
function sleep(millisecondsDuration) {
return new Promise((resolve) => {
setTimeout(resolve, millisecondsDuration);
});
}