xxxxxxxxxx
66
//https://forum.processing.org/two/discussion/23870/p5js-problem-with-asynchronous-video-loading-playing
//https://p5js.org/reference/#/p5/createVideo
var stage = 1;
var videos = [];
var whichVideo = 0;
function preload() {
videos[0] = createVideo("pouce.mp4");
videos[1] = createVideo("pouce2.mp4");
videos[2] = createVideo("pouce3.mp4");
videos[3] = createVideo("pouce4.mp4");
}
function setup() {
createCanvas(400, 400);
videos[0].hide();
videos[2].hide();
videos[1].hide();
videos[3].hide();
}
function draw() {
//background(255);
if (stage === 1) {
if (frameCount % 1 == 0) {
whichVideo = (whichVideo + 1) % videos.length;
stage = 2;
playTheVideo();
}
} else {
image(videos[whichVideo], 0, 0, 400, 400);
text("Video " + whichVideo, 100, 100);
}
/*
if (stage === 1) {
if (frameCount % 80 == 0) {
whichVideo = (whichVideo + 1) % videos.length;
stage = 2;
playTheVideo();
}
}
*/
}
function playTheVideo() {
videos[whichVideo].play();
videos[whichVideo].onended(videoOver);
}
function videoOver() {
console.log("stopping video now");
videos[whichVideo].pause();
videos[whichVideo].hide();
stage = 1;
}