# Need Help / Processing change video if

**URL:** https://discourse.processing.org/t/need-help-processing-change-video-if/37566
**Category:** Libraries
**Tags:** homework
**Created:** [June 15, 2022, 9:29pm UTC](https://discourse.processing.org/t/need-help-processing-change-video-if/37566 "2022-06-15T21:29:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Player07781](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@Player07781](https://discourse.processing.org/u/Player07781)
#### Post date: [June 15, 2022, 9:29pm UTC](https://discourse.processing.org/t/need-help-processing-change-video-if/37566/1 "2022-06-15T21:29:34Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)
> 
> 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?

```auto
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;
  }
}

```

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [June 16, 2022, 2:41am UTC](https://discourse.processing.org/t/need-help-processing-change-video-if/37566/2 "2022-06-16T02:41:53Z")

</div>

Hello @Player,

I trimmed down your code for testing the logic:

```auto
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/draw_.html)  
[https://processing.org/reference/keyPressed\_.html](https://processing.org/reference/keyPressed_.html)

`:)`

---

<div class="post-metadata">

### Author: ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)
#### Post date: [June 16, 2022, 7:09am UTC](https://discourse.processing.org/t/need-help-processing-change-video-if/37566/3 "2022-06-16T07:09:34Z")

</div>

> Deleted … as full solutions for category homework not welcome.
