Lagging Video Playback

Hi all, I’m new, so please forgive me for the multiple inefficiencies you will probably see in my code. What I’m most curious about though is procedure/method.

I am trying to make a 3 person challenge/game. There are three buttons and when each are being held down by a different person, a short .mov plays which is about 20MB big. As they watch, they have to try and keep themselves from jumping. If they do they might take their fingers off the button and stop the video. To continue through the video, no one can jump or else it starts over. Keep note that this is still a work in progress, and I’m not concerned about how the video will restart or how to get text and some sort of time counter in there (if you have suggestions though, don’t hesitate to mention them XD)

What I am unable to figure out though, is why I have at least a 5-12 second delay with the starting and stopping of the video every time I press or release the buttons. Right now, the .mov is being played when my board sends the number 3 to processing rather than the number 1.When I look at the printing lines however, there is virtually no delay with the buttons and the 3 vs. 1 signaling to processing. However the video does not kick in or out until much much later.

I feel like I’m doing this is a roundabout way. Is there a delay because I’m blasting signals every millisecond, have too big a video, or something else I’m unaware of? I tried exporting as standalone, and that resulted in just a gray screen. A general point in the right direction would be helpful, thanks so much! Here is the code for a better look at what I’m doing:

Processing

import processing.serial.*;
import cc.arduino.*;
Arduino arduino;
import processing.video.*;
Movie myMovie;
Serial myPort;

int inByte = 0;
int trans = 0;
int opaq = 255;


void serialEvent (Serial myPort) {
  int inByte = myPort.read();
  println(inByte);
}

void setup() {
size (1920, 1080, P2D);
  myPort = new Serial(this, Serial.list()[0], 9600);
  myMovie = new Movie(this, "shocktest.mov");

}

void draw() {
background(0);
  
  if (0 < myPort.available()) {
    inByte = myPort.read();
  }
  
imageMode(CENTER);
image(myMovie, 512, 384);
myMovie.loop();
rectMode(CENTER);
rect(512,384,1920,1080);
  
  if (inByte == 3) {
    myMovie.speed(1);
    fill(0,0,0,trans);
  } else {
    myMovie.speed(0);
    fill(0,0,0,opaq);
 }
}

Arduino

const int buttonPinOne = 2;
const int buttonPinTwo = 4;
const int buttonPinThree = 7;

int buttonStateOne = 0;
int buttonStateTwo = 0;
int buttonStateThree = 0;

void setup() {
 Serial.begin(9600);
 pinMode(buttonPinOne, INPUT);
 pinMode(buttonPinTwo, INPUT);
 pinMode(buttonPinThree, INPUT); 
}

void loop() {
  buttonStateOne = digitalRead(buttonPinOne);
  buttonStateTwo = digitalRead(buttonPinTwo);
  buttonStateThree = digitalRead(buttonPinThree);
  
  if (buttonStateOne == HIGH && buttonStateTwo == HIGH && buttonStateThree == HIGH) {
    Serial.write(3);
  }
  else {
    Serial.write(1);}
    
}
 Serial.begin(9600);

You could cut your delay by 88% by using a higher speed.

void serialEvent (Serial myPort) {
  int inByte = myPort.read();
  println(inByte);
}

A local variable that goes out of scope as soon as it's printed. How useful. NOT!

Why do you have a local variable with the same name as a global variable?

If you have a serialEvent() callback, why are you ALSO trying to read serial data in draw()? Knock that sh*t off!

imageMode(CENTER);
image(myMovie, 512, 384);
myMovie.loop();
rectMode(CENTER);
rect(512,384,1920,1080);

Does this REALLY belong in draw()? It looks like this should be in setup().