Loading...
Logo
Processing Forum
i am a grad student and new to processing
i am working on a piece with an array of video clips
i want the array to be accessed consecutively until the array has been completed at which point it would begin at zero
again
at the moment the mouse press sets it back to the beginning
i am not sure how to fix this
can anyone help?
please find my code below
thanks


import processing.video.*;

int maxmyMovies=5
;  //total # movies
int myMoviesIndex=0;  //initial movie to be displayed

Movie[] myMovies = new Movie[maxmyMovies] ; //declare array of movies

boolean someoneIsThere = false;


void setup( ){
 
  size(1280, 720);
   for (int i=0; i<myMovies.length; i++) {
    myMovies[i] = new Movie(this, "trans"+i+".mov");  //loading movies into the array
  }
  myMovies[myMoviesIndex].loop(); //play the first movie
}
void draw() {
  image(myMovies[myMoviesIndex], 0, 0, 1280, 720);   //display one movie
 
  if (myMovies[myMoviesIndex].time() >= myMovies[myMoviesIndex].duration()) {
    // the current movie is done
   
    if (someoneIsThere) {
      nextMovie();
      someoneIsThere = false;
    }
    else {
      myMovies[myMoviesIndex].stop(); // stop the current movie
      myMoviesIndex = 0;
      myMovies[myMoviesIndex].loop();
    }
  }
 
 
  fill(255);
  text(myMovies[myMoviesIndex].time(), 30, 30);
  text(myMovies[myMoviesIndex].duration(), 30, 60);
}


void movieEvent(Movie myMovies) {
  myMovies.read();  //read new frames from movie
}


void mousePressed() {
  someoneIsThere = true;
}

void nextMovie() {
  myMovies[myMoviesIndex].stop(); // stop the current movie
  myMoviesIndex=(myMoviesIndex+1) % myMovies.length;  //increment movie by one and return to zero once size of array is reached
  myMovies[myMoviesIndex].play(); // play the next movie
}


Replies(4)

I don't use that library, but it looks like what you are looking for is modulo:  http://processing.org/reference/modulo.html

Use it like this:
Copy code
  1. int index = 0;

  2. // A sample list in alphabetic order to show modulo working below
  3. String[] example = {
  4.   "Apple", "Banana", "Cranberry", "Durian", "Entawak"
  5. };

  6. void setup() {
  7.   size(100, 100);
  8. }

  9. void draw() {
  10.   int loopedIndex = (index % example.length);
  11.   println(index+", "+example[loopedIndex]);
  12.   index++;
  13. }
it was already looping through the array
but i am trying to get it to pick up at the next point in the array
as the mouse is pressed or not pressed
i.e. it is a linear string of video clips which can be interrupted and then pick
up at the next point in the array
i hope that makes sense?

 I think the problem is at line "  myMoviesIndex = 0;" and also the chain of testing is a bit confused ... well an example says more than a  thousand words :) I'm not testing if some one is there as mouse can't be pressed by some ghost, maybe a robot, but not a ghost... so i called  nextMovie straight form mousePressed.

Copy code
  1. import processing.video.*;

  2. int maxmyMovies=3;  //total # movies
  3. int myMoviesIndex=0;  //initial movie to be displayed

  4. Movie[] myMovies = new Movie[maxmyMovies] ; //declare array of movies

  5. boolean movieDone = false;


  6. void setup( ) {

  7.   size(1280, 720); 
  8.   for (int i=0; i<myMovies.length; i++) {
  9.     myMovies[i] = new Movie(this, "comedy"+nf(i, 2)+".mov");  //loading movies into the array
  10.   }
  11.   myMovies[myMoviesIndex].loop(); //play the first movie
  12. }
  13. void draw() {
  14.   image(myMovies[myMoviesIndex], 0, 0, 1280, 720);   //display one movie

  15.   if (myMovies[myMoviesIndex].time() >= myMovies[myMoviesIndex].duration()) {
  16.     // the current movie is done


  17.     myMovies[myMoviesIndex].stop(); // stop the current movie 
  18.     movieDone = true;
  19.   }



  20.   fill(255);
  21.   text(myMovies[myMoviesIndex].time(), 30, 30); 
  22.   text(myMovies[myMoviesIndex].duration(), 30, 60);
  23. }


  24. void movieEvent(Movie myMovies) {
  25.   myMovies.read();  //read new frames from movie
  26. }


  27. void mousePressed() { 

  28.   if(movieDone){
  29.   nextMovie();
  30.   movieDone = false;
  31.   }
  32. }

  33. void nextMovie() {
  34.   myMovies[myMoviesIndex].stop(); // stop the current movie
  35.   myMoviesIndex=(myMoviesIndex+1) % myMovies.length;  //increment movie by one and return to zero once size of array is reached
  36.   myMovies[myMoviesIndex].play(); // play the next movie
  37. }

vk,
thanks
the mouse pressed is a sub in for a sensor
eventually the piece will be activated by someone being there and not the mouse press
sorry am inarticulate (learning the language)
appreciate the help
clem