Total noob. Trying to run the code below, but receiving this error:
ArrayIndexOutOfBoundsException: Coordinate out of bounds!
This is all too new for me to figure out.
I'm running Processing 1.1 on Ubuntu 9.10, with the gsvideo library.
Here's my code:
Code:import codeanticode.gsvideo.*;
//import processing.video.*; // import the video package
PFont font; // a reference to your font
GSMovie trashMovie; // a reference to your movie
// all of these files go in the "data/" directory
String movieFile = "test3.avi"; // the name of the video file
String timestampsFile = "timestamps_"+movieFile+".txt"; // the name of the ts file
String captionsFile = "captions.txt"; // the name of the captions file.
float[] timestamps; // an array of the loaded timestamps
String[] captionWords; // an array of the loaded caption words
void setup() {
size(640, 480); // set the size of the screen
trashMovie = new GSMovie(this, movieFile); // load the movie
trashMovie.loop(); // make it a looping movie
loadTimestamps(timestampsFile); // load the timestamps
loadCaptions(captionsFile); // load the caption(s)
font = loadFont("Serif-48.vlw"); // load th font
textFont(font,48); // set the font
}
// this is the main draw loop
void draw() {
image(trashMovie,0,0); // draw the video frame
String caption = getText(trashMovie.time()); // get the current caption
fill(255,255,0,200); // make the text yellowish
text(caption,10,240,620,240); // draw the text into a box
}
// returns as many words from the caption as there have been mouth movements
String getText(float time) {
int numberOfMouthMovementsSoFar = 0;
for(int i = 0; i < timestamps.length; i++) {
if(time >= timestamps[i]) {
numberOfMouthMovementsSoFar++;
}
else {
break;
}
}
StringBuffer sb = new StringBuffer();
for(int i = 0; i < numberOfMouthMovementsSoFar; i++) {
sb.append(captionWords[i%captionWords.length]); // wrap around
sb.append(" ");
}
return sb.toString();
}
// loads the timestamps from a file
void loadTimestamps(String t) {
String[] ts = loadStrings(t);
timestamps = new float[ts.length];
for(int i = 0; i < ts.length; i++) {
timestamps[i] = Float.parseFloat(ts[i]);
}
}
// loads the caption from a file
void loadCaptions(String c) {
String caption = loadStrings(captionsFile)[0]; // gets the first line in the file
captionWords = split(caption, " ");
}
void movieEvent(GSMovie moov) {
moov.read();
}