import processing.video.*;
Movie movie;
float time = 0;
float[] inOutTimes = {0, 0}; // in and out points of video cut
boolean[] pushed = {false, false}; //push once for in time, push again for out time
void setup() {
size(330, 250, P3D); //P3D?
background(0);
frameRate(30);
movie = new Movie(this, "duckcoversmall.mov"); //160x120 -- make it photojpg codec
movie.play();
fill(255, 0, 0);
}
void draw() {
if (pushed[0] && pushed[1]) {
if(movie.time() < inOutTimes[1]) {
image(movie, 0, height-120);
} else {
//movie.pause();
//movie.stop();
rect(0, height-120, 160, 120);
}
} else {
float ratio = mouseX/(float)width;
time = ratio*movie.duration();
movie.jump(time);
image(movie, 0, 0);
}
}
void movieEvent(Movie m) {
m.read();
}
void keyPressed() {
if (!pushed[0]) {
inOutTimes[0] = time;
movie.jump(time);
image(movie, width-160, 0);
pushed[0] = true;
} else if (!pushed[1]) {
inOutTimes[1] = time;
movie.jump(time);
image(movie, width-160, height-120);
pushed[1] = true;
movie.jump(inOutTimes[0]); //once pushed twice, then display video from first frame saved
} else {
movie.jump(inOutTimes[0]);
}
}