# How can i make a movie array? :S

**URL:** https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827
**Category:** Libraries
**Created:** [May 3, 2021, 8:44pm UTC](https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827 "2021-05-03T20:44:31Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![softailu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/softailu/32/13533_2.png) [@softailu](https://discourse.processing.org/u/softailu)
#### Post date: [May 3, 2021, 8:44pm UTC](https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827/1 "2021-05-03T20:44:31Z")

</div>

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!

```auto
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);
}

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 4, 2021, 6:03am UTC](https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827/2 "2021-05-04T06:03:12Z")

</div>

> [@softailu](#):
>
> `misVideos[i].loop();`

I wouldn’t start all videos at once

Instead use an index currentVideo to hold the number

---

<div class="post-metadata">

### Author: ![softailu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/softailu/32/13533_2.png) [@softailu](https://discourse.processing.org/u/softailu)
#### Post date: [May 31, 2021, 12:31am UTC](https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827/3 "2021-05-31T00:31:05Z")

</div>

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!

```auto
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();
}

```

```auto
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();
  }

```

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 31, 2021, 5:32am UTC](https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827/4 "2021-05-31T05:32:44Z")

</div>

> [@softailu](#):
>
> ```auto
> //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");
> }
> 
> ```

//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");
}

```

---

<div class="post-metadata">

### Author: ![softailu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/softailu/32/13533_2.png) [@softailu](https://discourse.processing.org/u/softailu)
#### Post date: [May 31, 2021, 1:19pm UTC](https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827/5 "2021-05-31T13:19:17Z")

</div>

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

```auto
//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?

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 31, 2021, 3:28pm UTC](https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827/6 "2021-05-31T15:28:13Z")

</div>

```auto

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 
//

```

---

<div class="post-metadata">

### Author: ![softailu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/softailu/32/13533_2.png) [@softailu](https://discourse.processing.org/u/softailu)
#### Post date: [May 31, 2021, 4:02pm UTC](https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827/7 "2021-05-31T16:02:17Z")

</div>

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

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

```

1. dead code

```auto
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

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [May 31, 2021, 4:46pm UTC](https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827/8 "2021-05-31T16:46:20Z")

</div>

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

---

<div class="post-metadata">

### Author: ![softailu](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/softailu/32/13533_2.png) [@softailu](https://discourse.processing.org/u/softailu)
#### Post date: [May 31, 2021, 5:43pm UTC](https://discourse.processing.org/t/how-can-i-make-a-movie-array-s/29827/9 "2021-05-31T17:43:20Z")

</div>

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:

```auto
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( );
}

```

```auto

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]);
  }
}

```
