Need Help / Processing change video if

please format code with </> button * homework policy * asking questions

I have tried using this code but the code I put in 4 videos but the video only plays the first video as if other videos are playing after the first video. Is there a way to solve it?
import processing.video.*;

Movie theMov; 
int VideoPlaying;

boolean Vid1 = false;
boolean Vid2 = false;
boolean Vid3 = false;
boolean Vid4 = false;

//Videos
Movie Video1; 
Movie Video2; 
Movie Video3;
Movie Video4;

//Fim Videos

void setup() { 
  size(600, 300);

  //videos
  Video1 = new Movie(this, "video1.mp4");
  Video2 = new Movie(this, "video2.mp4");
  Video3 = new Movie(this, "video3.mp4");
  Video4 = new Movie(this, "video4.mp4");
  //Fim videos

}

void draw() { 

  toogle();
  if (Vid1) {

    println("video1");
    Video2.stop();
    Video3.stop(); 
    Video4.stop();
    background(0);
    Video1.play();
    background(0);
    image(Video1, 0, 0, width, height);
  }

  if (Vid2) {
    println("video2");
    Video1.stop();
    Video3.stop(); 
    Video4.stop();
    background(0);
    Video2.play();
    image(Video2, 0, 0, width, height);
  }

  if (Vid3) {
    println("video3");
    Video1.stop();
    Video2.stop();
    Video4.stop();
    background(0);
    Video3.play();
    image(Video3, 0, 0, width, height);
  }

  if (Vid4) {
    println("video4");
    Video1.stop();
    Video2.stop();
    Video3.stop();
    background(0);
    Video4.play();
    image(Video4, 0, 0, width, height);
  }
}
void movieEvent(Movie m) { 
  m.read();
} 

void keyPressed() {


  //video
  if (key == '1') {
    VideoPlaying = 1 ;
    println(VideoPlaying);
  }

  if (key == '2') {
    VideoPlaying = 2 ;
    println(VideoPlaying);
  }

  if (key == '3') {
    VideoPlaying = 3 ;
    println(VideoPlaying);
  }

  if (key == '4') {
    VideoPlaying = 4 ;
    println(VideoPlaying);
  }
  //Fim Video

}




void toogle() {

  if (VideoPlaying == 1) {
    Vid1 = true;
    Vid2 = false;
    Vid3 = false;
    Vid4 = false;
  }

  if (VideoPlaying == 2) {
    Vid1 = false;
    Vid2 = true;
    Vid3 = false;
    Vid4 = false;
  }

  if (VideoPlaying == 3) {
    Vid1 = false;
    Vid2 = false;
    Vid3 = true;
    Vid4 = false;
  }

  if (VideoPlaying == 4) {
    Vid1 = false;
    Vid2 = false;
    Vid3 = false;
    Vid4 = true;
  }
}

Hello @Player,

I trimmed down your code for testing the logic:

int VideoPlaying;

boolean Vid1 = false;
boolean Vid2 = false;
boolean Vid3 = false;
boolean Vid4 = false;

void setup() { 
  size(600, 300);
}

void draw() { 

  //This is executing 60 times a second!
  //toogle();
  
  //if (Vid1) println("video1");
  //if (Vid2) println("video2");
  //if (Vid3) println("video3");
  //if (Vid4) println("video3");
}

void keyPressed() {

  //video
  if (key == '1') {
    VideoPlaying = 1 ;
    println(VideoPlaying);
  }

  if (key == '2') {
    VideoPlaying = 2 ;
    println(VideoPlaying);
  }

  if (key == '3') {
    VideoPlaying = 3 ;
    println(VideoPlaying);
  }

  if (key == '4') {
    VideoPlaying = 4 ;
    println(VideoPlaying);
  }

}


void toogle() {

  if (VideoPlaying == 1) {
    Vid1 = true;
    Vid2 = false;
    Vid3 = false;
    Vid4 = false;
  }

  if (VideoPlaying == 2) {
    Vid1 = false;
    Vid2 = true;
    Vid3 = false;
    Vid4 = false;
  }

  if (VideoPlaying == 3) {
    Vid1 = false;
    Vid2 = false;
    Vid3 = true;
    Vid4 = false;
  }

  if (VideoPlaying == 4) {
    Vid1 = false;
    Vid2 = false;
    Vid3 = false;
    Vid4 = true;
  }
}

Read the comments!

Try putting the code in draw() into keyPressed() so it only executes once and see what happens.

This was not tested with video.

References:
https://processing.org/reference/draw_.html
https://processing.org/reference/keyPressed_.html

:)

Deleted … as full solutions for category homework not welcome.