Movie control in Processing

This is a quick post to show how to control movie playback with Processing.

/**
 * Loop. 
 * 
 * Shows how to load and play a QuickTime movie file.  
 *
 */

import processing.video.*;

Movie movie;

void setup() {
  size(560, 406);
  background(0);
  // Load and play the video in a loop
  movie = new Movie(this, "tac.mov");
  movie.loop();
}


void draw() {
  image(movie, 0, 0, width, height);

  if (mousePressed == true) {
    movie.play();
    movie.read();
  } else {
    movie.stop();
    fill(0);
    rect(0, 0, width, height);
  }
  
}
Code language: Java (java)

There’s the code. It’s the basic default code to show a movie. But what if you want some event (mouse press, input from Arduino, etc) to control if and when the movie plays.

Not so intuitive, and hence this post.

The trick is to use the play() and read() methods in the if…else statement. In the code above. If the mouse button is pressed, then the movie will play from the beginning.

And if you want the video to disappear after the video is played, then after the movie stops, cover the draw window with a rectangle (filled with black, in this example).

Share and Enjoy:
  • Print
  • PDF
  • RSS

Related Posts:

  • No Related Posts