How can i make a movie array? :S

Hi! I need help with a problem that I cannot solve.
I want to make an array of several .mov recordings and I can’t get it to work.

My main idea is to be able to load more than 10 videos in an array and then from mouse clicks make them appear randomly.

This is the code I have so far, can you help me? Thank you!

import processing.video.*;

int cantidad = 5;
Movie[] misVideos = new Movie[cantidad];

//String[] nombreVideos = { "trazo00.mov", "trazo0.mov", "trazo02.mov", "trazo03.mov", "trazo04.mov", };


void setup() {
  size(800, 800);

  for ( int i = 0; i < misVideos.length; i++) {

    misVideos[i] = new Movie(this, "trazo"+nf(i, 2) + ".mov");
    misVideos[i].loop();
    // misVideos[i] = new Movie(this, nombreVideos[i]);
    //  String nombre = "trazo"+nf(i, 2)+ ".mov";
  }
}

void movieEvent(Movie[] misVideos) {
  for ( int i = 0 ; i < misVideos.length; i++) {
  }
  misVideos[].read();
}

void draw() {
  image(misVideos[],0,0);
}


I wouldn’t start all videos at once

Instead use an index currentVideo to hold the number

Thanks for the help.
I have been able to make the array but now I need help to convert it into an object.
The code without objects works, but when I try to do it I get errors.

What am I doing wrong?

I leave the code that works and the new one with the object that does NOT work.

Thanks!

WORKING CODE

import processing.video.*;

int maxVideos= 5;
Movie[] misVideos=new Movie[maxVideos] ;
ArrayList<PVector> videoPos = new ArrayList<PVector>();
ArrayList<Movie> videoPlay = new ArrayList<Movie>();
//randomize var
int rand = int(random(maxVideos)); 


void setup() {
  size (1100, 600, P2D);
  frameRate (60);
  background(0);

  for (int i = 0; i < misVideos.length; i ++ ) {
    misVideos[i] =  new Movie (this, "trazo"+nf(i, 2) + ".mov");
  }
}

void mouseReleased() {
  rand = int(random(maxVideos)); //Re-chooses the video
  //store position:
  videoPos.add(new PVector(mouseX, mouseY));
  // add video to the list
  videoPlay.add(misVideos[rand]);
}

void draw() {

  background(0);

  if (videoPlay.size() > 0) {
    for (int i = 0; i< videoPlay.size(); i++ ) {
      videoPlay.get(i).play();
      imageMode(CENTER);
      image(videoPlay.get(i), videoPos.get(i).x, videoPos.get(i).y);
    }
  }

  //frameRate
  frame.setTitle("fps" + frameRate);
}

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

NOT WORKING
import processing.video.*;


ArrayList<PVector> videoPos = new ArrayList<PVector>();
ArrayList<Movie> videoPlay = new ArrayList<Movie>();

 //Objet declaration:
Pincelada p;


void setup() {
  size (1100, 600, P2D);
  frameRate (60);
  background(0);
  
  //Inicialization:
  p = new Pincelada();
  
}


void draw() {

  background(0);
  //frameRate
  frame.setTitle("fps" + frameRate);


}

void mouseReleased() {
  p.cuandoClickeo( );
  
}

////////////////////////

class Pincelada {

  //1. Atributos
  int maxVideos;
  Movie[] misVideos;

  //random var:
  int rand;


  //2. Constructor
  Pincelada( Movie[] misVideos  ) {

    Movie[] misVideos = new Movie[maxVideos];
    int maxVideos = 5;

    for (int i = 0; i < misVideos.length; i ++ ) {
      misVideos[i] =  new Movie (this, "trazo"+nf(i, 2) + ".mov");
    }


    //3. Métodos

    void dibujar(  ) {   /*<---ERROR unexpected token: void*/
      if (videoPlay.size() > 0) {
        for (int i = 0; i< videoPlay.size(); i++ ) {
          videoPlay.get(i).play();
          imageMode(CENTER);
          image(videoPlay.get(i), videoPos.get(i).x, videoPos.get(i).y);
        }
      }
    }

    void mouseReleased() {
      rand = int(random(maxVideos)); //randomize videos
      //guardo la posición:
      videoPos.add(new PVector(mouseX, mouseY));
      // agrego un video a la lista
      videoPlay.add(misVideos[rand]);
    }

    //draw videos


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

    read();
  }



//2. Constructor
Pincelada( ) {

misVideos = new Movie[maxVideos];
maxVideos = 5;

for (int i = 0; i < misVideos.length; i ++ ) {
  misVideos[i] =  new Movie (this, "trazo"+nf(i, 2) + ".mov");
}

Hi, thanks for the answer but i’m still getting the same error "The constructor “Movie(Pinceladas, String)” does not exist.

//2. Constructor
  Pinceladas() {

    misVideos = new Movie[maxVideos];
    maxVideos = 5;

    for (int i = 0; i < misVideos.length; i ++ ) {
      misVideos[i] =  new Movie (this, "trazo"+nf(i, 2) + ".mov");
    }

what i’m doing wrong?


import processing.video.*;

ArrayList<PVector> videoPos = new ArrayList<PVector>();
ArrayList<Movie> videoPlay = new ArrayList<Movie>();

//Objet declaration:
Pincelada p;


void setup() {
  size (1100, 600, P2D);
  frameRate (60);
  background(0);

  //Inicialization:
  p = new Pincelada(this);
}


void draw() {

  background(0);
  //frameRate
  // surface.setTitle("fps" + frameRate);
}

//draw videos


void movieEvent(Movie m) {
  p.misVideos[0].read();
}

void mouseReleased() {
  p.mouseReleased( );
}

/////////////////////////////////////////////////////////////////////////

class Pincelada {

  //1. Atributos
  int maxVideos;
  Movie[] misVideos;

  //random var:
  int rand;

  //2. Constructor
  Pincelada(PApplet myApplet) {

    maxVideos = 2;
    misVideos = new Movie[maxVideos];

    for (int i = 0; i < misVideos.length; i++ ) {
      println( "trazo"+nf(i, 2) + ".mov"); 
      misVideos[i] =  new Movie (myApplet, "trazo"+nf(i, 2) + ".mov");
      misVideos[i].loop(); 
      break;
    }
  }//Constructor

  //3. Métodos
  void dibujar(  ) {   
    if (videoPlay.size() > 0) {
      for (int i = 0; i< videoPlay.size(); i++ ) {
        videoPlay.get(i).play();
        imageMode(CENTER);
        image(videoPlay.get(i), videoPos.get(i).x, videoPos.get(i).y);
      }
    }
  }

  void mouseReleased() {
    rand = int(random(maxVideos)); //randomize videos
    //guardo la posición:
    videoPos.add(new PVector(mouseX, mouseY));
    // agrego un video a la lista
    videoPlay.add(misVideos[rand]);
  }

  // read();
}//class 
//

Thank you very much for your help, I really think there is a breakthrough.

Still, I run the code with your modifications and nothing happens, the screen goes black.

It throws me two errors:

  1. the value of the parameter m is not used
void movieEvent(Movie m) {
  p.misVideos[0].read();
}
  1. dead code
for (int i = 0; i < misVideos.length; i++ ) { //<--- HERE
      println( "trazo"+nf(i, 2) + ".mov"); 
      misVideos[i] =  new Movie (myApplet, "trazo"+nf(i, 2) + ".mov");
      misVideos[i].loop(); 
      break;
    }

I don’t really understand about the PApplet myApplet parameters, but I’m doing some research on it.

Thank you very much again

1 Like

Yeah, I made the numbers of movies too small

Also, get rid of break; inside the for loop
Also say loop or play only with the last movie not all of them

The thing with this is interesting - you can search ir here in the forum

I am not sure how the movie event bit works when the movie is inside a class

It works! Thanks to your valuable contributions and last comments I was able to make the code work in an acceptable way.
Now I have to start investigating how to add a color mask to modify the strokes.
I would like to have a color palette assigned and that are varied randomly.
If you come up with a suggestion I will be very grateful, otherwise what you have contributed is invaluable.

Thanks!

Here’s the working code:

import processing.video.*;

ArrayList<PVector> videoPos = new ArrayList<PVector>();
ArrayList<Movie> videoPlay = new ArrayList<Movie>();

//Objet declaration:
Pincelada p;


void setup() {
  size (1100, 600, P2D);
  frameRate (60);
  background(0);

  //Inicialization:
  p = new Pincelada(this);
}


void draw() {

  background(0);

  p.dibujar();
  //frameRate
  //surface.setTitle("fps" + frameRate);
}


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

void mouseReleased() {
  p.cuandoSueltoElMouse( );
}


class Pincelada {

  //1. Atributos
  int maxVideos;
  Movie[] misVideos;

  //random var:
  int rand;

  //2. Constructor
  Pincelada(PApplet myApplet) {

    maxVideos = 4;
    misVideos = new Movie[maxVideos];

    for (int i = 0; i < misVideos.length; i++ ) {
      println( "trazo"+nf(i, 2) + ".mov"); 
      misVideos[i] =  new Movie (myApplet, "trazo"+nf(i, 2) + ".mov");
      //misVideos[i].loop();
    }
  }

  //3. Métodos
  void dibujar() {   
    if (videoPlay.size() > 0) {
      for (int i = 0; i< videoPlay.size(); i++ ) {
        videoPlay.get(i).play();
        imageMode(CENTER);
        image(videoPlay.get(i), videoPos.get(i).x, videoPos.get(i).y);
      }
    }
  }

  void cuandoSueltoElMouse() {
    //randomizar los videos
    rand = int(random(maxVideos)); 
    //guardo la posición:
    videoPos.add(new PVector(mouseX, mouseY));
    // agrego un video a la lista
    videoPlay.add(misVideos[rand]);
  }
}

1 Like