We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey everyone,
I'm creating a movie player program with an Arduino board. I've successfully made the program play one movie file when I wave my hand in front of the Arduino PIR monitor, I just want it to randomly select from an array of other video files. Any help would be appreciated.
Here's my code so far...
import processing.video.*;
import processing.serial.*;
Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph, original 1
float inByte = 0;
String[] movieNames = { "1.mpg", "2.mpg", "3.mpg", "4.mpg"};
Movie[] movee = new Movie[movieNames.length];
void setup() {
  fullScreen();
  background(0);
  myPort = new Serial (this, "COM6", 9600);
  myPort.bufferUntil('\n');
  for (int i=0; i<movieNames.length; i++) {
    movee[i] = new Movie(this, movieNames[i]);
  }
}
void draw() {
  for (int i = 0; i < movieNames.length; i++) {
    image(movee[0], 0, 0);
  }
}
void movieEvent(Movie m) {
  m.read();
}
void serialEvent(Serial myPort) {
  String inString = myPort.readStringUntil('\n');
  if (inString != null) {
    inString = trim(inString);
    inByte = float(inString);
    println(inByte);
    if (inByte == 1) {
      movee[0].stop();
      println("Playing video...");
      movee[0].play();
    }
  }
}
Answers
Lines 25 to 27 make no sense. You are looping over all the videos, which you don't want. And are then using movee 0 every time, which is certainly not what you want.
Use a variable to store which video is being played, change this in your serial event. Ditch the loop.
Relevant post:
https://forum.processing.org/two/discussion/22640/can-anyone-help-me-find-what-s-wrong-with-my-code-for-a-video-player-based-off-sensor-reading#latest
Kf
Thanks!