Can I have conditionals in movieEvent?

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.

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;
  }
}
1 Like

the basic operation ( here keyboard example )

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

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

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

2 Likes

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

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

1 Like