How to play a video using keyPressed etc.?

edited May 2016 in Library Questions

Hi. I am very very new to Processing. I am working on a project that involves Makey Makey, and I need to figure out how to make a video play smoothly using keys or a mouse. I am using keyPressed now for this, but the video comes out all twitchy, probably because you have to hold the key for the whole duration of the movie in order for it to play. Is there a better way to do it? I was thinking that mouseClicked or keyReleased or keyTyped would be better for this purpose, but I am not sure how to do it. Anyway, here is my code:

import processing.video.*;
Movie myMovie1, myMovie2, myMovie3;
boolean playMovie1=true;
boolean playMovie2=false;
boolean playMovie3=false;



void setup()
{
  size (displayWidth, displayHeight);
  background (0);


 myMovie1 = new Movie(this, "1.mp4");

 myMovie2 = new Movie(this, "2.mp4");

 myMovie3 = new Movie(this, "3.mp4");

}

void draw(){
background(0);
if(playMovie1==true){

myMovie1.play();
image(myMovie1,0, 0);
if(myMovie1.time()>=myMovie1.duration()){
myMovie1.stop();
playMovie1=false;

playMovie2=true;
}
}




if(playMovie3==true){

myMovie3.play();
image(myMovie3,0,0);
if(myMovie3.time()>=myMovie3.duration()){
myMovie3.stop();
playMovie3=false;
}
}
}


void movieEvent(Movie m){
m.read();
}

void keyPressed()

{

// PRESS LEFT OR RIGHT AFTER FIRST VIDEO
  if ((keyCode == RIGHT) || (keyCode == LEFT))

{
 if(playMovie2==true){

myMovie2.read();
myMovie2.play();
image(myMovie2,0,0);
if(myMovie2.time()>=myMovie2.duration()){
myMovie2.stop();
playMovie2=false;
playMovie3=true;
}}


 }}
This discussion has been closed.