Code is sometimes malfunctioning

I have a problem with my code. I use an Arduino to act as a keyboard, but after a while it stops working. Also, sometimes the menu stops playing and/or the video's stop triggering. Is there something in the code wich could generate unpredictable problems?

This is the code:

import processing.video.*;

import ddf.minim.*;

final static String[] fileNames = {
"Alice", "Amarins", "Dirksierd", "Eric", "Gerben", "Guido", "Hanna", "Jacco",
"Jan", "Jeroen", "Kaak", "Klaas", "Lolkje", "Mara", "Medewerker", "Merel", "Merlijn",
"Michel", "Niek", "Patrick", "Paul", "Peter", "Raar", "Raymond", "Remko", "Rene",
"Ronald", "Sakejan", "Siebe", "Sjef", "Voet", "Wander", "Wessel"};

final static int numSongs  = fileNames.length - 1;
final static AudioPlayer[] songs = new AudioPlayer[numSongs];

final  Minim minim = new Minim(this);

int startTime = -3000;
int idx;
int maxmyMovies = 25; 
int myMoviesIndex = 0;

Movie menuMovie;
Movie[] myMovies = new Movie[maxmyMovies];


void setup() {

  size(848, 480);
    for ( int idxb = 0; idxb != numSongs; 
  songs[idxb] = minim.loadFile( fileNames[idxb++] + ".wav") );

    menuMovie = new Movie(this, "Menu.MP4");
    for (int idx = 0; idx < myMovies.length; idx ++ ) {
    myMovies[idx] = new Movie(this, idx + ".mp4");
    }
  }

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


void draw() {
  if ((millis() - startTime >= 10000)){
    menuMovie.loop();
    image(menuMovie, 0, 0, 848, 480);
    }
    else
    {image(myMovies[myMoviesIndex], 0, 0, 848, 480); // Displaying one image}
    }
}


void keyPressed(){ 
  if ( (millis() - startTime <= 3000))
  {println("geduld jongeman...");}
  else {
    println(keyCode);
    songs[idx].rewind();
    songs[ (int) random(numSongs) ].play();

    final int k = keyCode;
    idx = k - 64;
    float index2 = random(0-28);
    if (idx >= 0 & idx < myMovies.length) {
    myMovies[myMoviesIndex].stop();
    myMovies[myMoviesIndex = idx].play();
    myMovies[myMoviesIndex = idx].volume(0);    
    }
    startTime = millis();
    println(millis());
    }
}


void stop() {
  for ( int idxb = 0; idxb!= numSongs; songs[idxb++].close() );
  minim.stop();
  super.stop();
}
Sign In or Register to comment.