# Can I have conditionals in movieEvent?

**URL:** <https://discourse.processing.org/t/can-i-have-conditionals-in-movieevent/16244>\
**Category:** Libraries\
**Created:** [December 8, 2019, 10:12am UTC](https://discourse.processing.org/t/can-i-have-conditionals-in-movieevent/16244 "2019-12-08T10:12:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lane](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@Lane](https://discourse.processing.org/u/Lane)\
**Post date:** [December 8, 2019, 10:12am UTC](https://discourse.processing.org/t/can-i-have-conditionals-in-movieevent/16244/1 "2019-12-08T10:12:46Z")

</div>

Hello! I am trying to code something where if one button is pressed then a video will play and when another button is pressed then a different video will play. I tried to stick the videos in a mouseClicked function, but the videos are jumpy if they are not in movieEvent. Can I have an if/else statement in movieEvent? This is the code I have right now.

```auto
import processing.video.*;
import processing.sound.*;

// videos
Movie cat;
Movie dog;

// buttons
Button b1; //sad face
Button b2; //happy face

void setup() {
  size(500, 500);

  cat = new Movie(this, "cat.mp4");
  cat.loop();

  dog = new Movie(this, "dog.mp4");
  dog.loop();

  b1 = new Button((width/2-80), (height/2+480), (30), (18), (width/2-80), (width/2-50), (height/2+480), (height/2+498));
  b2 = new Button ((width/2-42), (height/2+480), (30), (18), (width/2-42), (width/2-12), (height/2+480), (height/2+498));
}

void draw() {
  background(255);
  b1.display();
  b2.display();
}

void movieEvent() {
// code where cat will play when b1 is pressed and dog will play with b2 is pressed
}

class Button {
  color buttonC;
  float buttonX1;
  float buttonY1;
  float buttonW1;
  float buttonH1;
  float xBound1;
  float xBound2;
  float yBound1;
  float yBound2;
  boolean click;

  Button(float xPosit, float yPosit, float wid, float he, float xB1, float xB2, float yB1, float yB2) {
    //this.buttonC = color (#355C7D);
    this.buttonC=#B7B5B5;
    this.buttonX1=xPosit;
    this.buttonY1=yPosit;
    this.buttonW1=wid;
    this.buttonH1=he;
    this.xBound1=xB1;
    this.xBound2=xB2;
    this.yBound1=yB1;
    this.yBound2=yB2;
    this.click = false;
  }

  void display() {
    noStroke();
    fill(this.buttonC);
    rect(this.buttonX1, this.buttonY1, this.buttonW1, this.buttonH1);
  }

  boolean IsClicked() {
    if (mousePressed == true && mouseX>this.xBound1 && mouseY>this.yBound1 && mouseY<this.yBound2 && mouseX<this.xBound2) {
      click=true;
    }
    return click;
  }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 8, 2019, 11:39am UTC](https://discourse.processing.org/t/can-i-have-conditionals-in-movieevent/16244/2 "2019-12-08T11:39:00Z")

</div>

the basic operation ( here keyboard example )

```auto
import processing.video.*;

Movie mov;

void setup() {
  size(640, 360);
  mov = new Movie(this, "transit.mov");  
  mov.loop();
// mov.pause();
}

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

void draw() {
  background(255);
  image(mov, 0, 0);
}

boolean toggle = false;

void keyPressed() {
  if ( key == ' ' ) { 
    toggle = ! toggle;
    if ( toggle ) mov.pause();
    else mov.loop();
  }
}  

```

that you now ( additionally ) do with your mouse click button(s)

with 2 movies you might operate both

```auto
a.pause();
b.loop();

```

in the `movieEvent` need no extra code i think.  
( it is reading both … )

---

<div class="post-metadata">

**Author:** ![Lane](https://avatars.discourse-cdn.com/v4/letter/l/779978/32.png) [@Lane](https://discourse.processing.org/u/Lane)\
**Post date:** [December 8, 2019, 12:11pm UTC](https://discourse.processing.org/t/can-i-have-conditionals-in-movieevent/16244/3 "2019-12-08T12:11:58Z")

</div>

Can you please explain what the boolean toggle = false does? Thank you so much!

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 8, 2019, 12:19pm UTC](https://discourse.processing.org/t/can-i-have-conditionals-in-movieevent/16244/4 "2019-12-08T12:19:05Z")

</div>

it declares a global variable ( memory )  
what can be used  
like operated ( toggled ) by key pressed…  
or YOUR button logic

what it does?  
every time you press [space] key  
the value of ‘toggle’ changes  
and depending on that the video is stopped or played

* * *

actually that is not best style,  
i was searchin for something like  
`mov.isPlaying()`  
but not find it from that library.  
so i helped by a own memory variable
