lundi 28 février 2022

How can I randomize a video to play after another by pressing a key on Processing?

I'm quite new to Processing.

I'm trying to make Processing randomly play a video after I clear the screen by mouseclick, so I create an array that contain 3 videos and play one at a time.

Holding 'Spacebar' will play a video and release it will stop the video. Mouseclick will clear the screen to an image. The question is how can it ramdomize to another video if I press spacebar again after clear the screen.

I've been searching all over the internet but couldn't find any solution for my coding or if my logic is wrong, please help me.

Here's my code.

int value = 0;
PImage photo;
import processing.video.*;


int n = 3; //number of videos

float vidN = random(0, n+1);
int x = int (vidN);

Movie[] video = new Movie[3];
int rand = 0;

int index = 0;

void setup() {
  size(800, 500);
  frameRate(30);
  
  video = new Movie[3];
  video[0] = new Movie (this, "01.mp4");
  video[1] = new Movie (this, "02.mp4");
  video[2] = new Movie (this, "03.mp4");


  photo = loadImage("1.jpg");
}


void draw() {

}


void movieEvent(Movie video) {
  video.read();
}

void keyPressed() {

  if (key == ' ') {
    image(video[rand], 0, 0);
    video[rand].play();
  }
  
}

void mouseClicked() {
  if (value == 0) {
    video[rand].jump(0);
    video[rand].stop();
    background(0);
    image(photo, 0, 0);
  }
}



Aucun commentaire:

Enregistrer un commentaire