how to play a movie on mousePressed, with multiple other things happening.

edited November 2015 in Library Questions

Hello, I am a beginner, this is only my second 'serious' program. I am creating an 'interactive poster' for a school assignment. I have the poster loaded as a background image. I would like to have the mousePress function play a short video, if the mouse is clicked on a certain area of the screen. The part I'm having trouble with is which part of the PlayMovie functions to put in setup, which in draw, and which in mouseClicked. Each arrangement I have tried generates a different error, and none of them work so far. I have working programs for all the other components, but nothing where I can press the mouse and have it play the video, when there is a previous image in place. Can someone please help?

Answers

  • It sent automatically. Here is my code:

    import processing.video.*; Movie MyMovie; //declares a movie object

    PImage img; //This loads the image of the poster

    void setup() { //setup is code that only runs once size(1200, 1000); // maximum screen size specified in assignment background(0); // black img = loadImage("ProcessingPoster03_b.jpg"); MyMovie = new Movie(this, "GreenCubeMatrix.mov"); MyMovie.play(); //m.play() to play once
    } //m.loop() to loop continuously.

    void draw() { //loops forever, only one call to draw allowed per sketch. So how then do I do multiple things? image(img, 0, 0); }

    void mouseClicked() { println(mouseX, mouseY); image(myMovie, mouseX, mouseY)

    if(inRectangle(mouseX, mouseY, 50, 50, 100, 100)) { //do video image(MyMovie,0,0, 200, 200); // could go in the void draw function?

    void movieEvent(Movie m) { // could go in void draw void movieEvent(Movie m) { DOES THIS GO HERE? m.read(); }

    }

    } else { // or else println("Click to play movie"); // encourage user interaction }

    }

    boolean inRectangle(float mouseX, float mouseY, float ULX, float ULY, float LRX, float LRY) { if(mouseX < ULX) return false; if(mouseX > LRX) return false; if(mouseY < ULY) return false; if(mouseY > LRY) return false; return true; }

  • void mousePressed() {
    //events
    }

Sign In or Register to comment.