Playing different videos from mouse coordinates?

Hi! I’m new to processing. I’m trying to make a program to play different videos depending upon the mouse coordinates. So open up a blank window, then if the mouse coordinates are between these sets of numbers, play video number one. Then if the mouse coordinates are between these other sets of numbers, play video 2. etc.

I was able to come up with a code to change the text depending upon the mouse coordinates. Here’s an excerpt:

void setup() {
  size(934,887);
}

void draw(){
  background(0);
//if x is between 46 and 339 AND y is between 46 and 249, then 1
  if((46<mouseX && mouseX<339)&&(46<mouseY && mouseY<249)){
    textSize(20);
    text("1", width/2, height/2);
  }

//if x is between 46 and 339 AND y is between 249 and 464, then 2
  if((46<mouseX && mouseX<339)&&(249<mouseY && mouseY<464)){
    textSize(20);
    text("2", width/2, height/2);
  }

But instead of having different text, I want to play different videos. I’ve watched the processing tutorial videos on loading/playing video files but they have different void setup, void draw stuff and I’m not sure how to combine it with my mouse tracking code. I was thinking of just keeping my code and then under every if(), just putting in the video code like this:


but it doesn’t work because now I have multiple void setups and other issues. Thanks

a) Declare variables at the top of your program.
b) Initialise or instantiate these in setup().
c) Then perform operations on these in draw().

import processing.video.*;

Movie video1, video2;

void setup() {
    fullScreen();
    video1 = new Movie(this, "video-one.mov");
    video2 = new Movie(this, "video-two.mov");
}

void draw() {
    if (mouseX < width/2) {
	    // left half of screen
	    video1.loop();

        if (video1.available()) {
            video1.read();
    	    image(video1, 0, 0, width, height);
        }
    } else {
	    // right half of screen
        video2.loop();
        
        if (video2.available()) {
            video2.read();
            image(video2, 0, 0, width, height);
        }
    }
}
1 Like