Random video select code.

edited January 2016 in Library Questions

Hi everyone! I have run into a problem with some code. The code is made so when the user presses A, S or D it will load one of three files assigned for each letter. However, when I press play it comes up with the error: "expecting RPAREN, found ';' syntax error, maybe a missing perenthesis?" for line 32.

does anyone know what the problem is here? Thanks :)

import processing.video.*;

String[] one = {
  "ag1.mov", "ag2.mov", "ag3.mov", "am1.mov", "am2.mov", "am3.mov",
  "tran1.mov", "tran2.mov", "tran3.mov"
};


Movie myMovie;

int a = 0;
float md = 0;
float mt = 0;

void setup()
{
  size(400, 400, P2D);
}


void draw()
{

  image(myMovie, 0, 0, width, height);

}

void keyPressed()
{
if (key == 'a' || key == 'A') 
  {
    myMovie = new Movie(this, int(random(1, 3));
    myMovie.play();
  }

  else if (key == 's' || key == 'S')
  {
    myMovie = new Movie(this, int(random(4, 6));
    myMovie.play();
  }

  else if (key == 'd' || key == 'D')
  {
    myMovie = new Movie(this, int(random(7, 9));
    myMovie.play();
  }

  else 
  {
    myMovie.stop();
  }
}
Tagged:

Answers

  • edited January 2016

    Line #32 -> Missing an extra closing parens. Tip: Hit CTRL+T inside PDE. O:-)

  • edited January 2016

    You need to add a right bracket before the semicolon. Change it into this myMovie = new Movie(this, int(random(1, 3)));

    The same goes for lines 38 & 44 as well.

  • edited January 2016

    thank you so much for your fast reply GoToLoop & Alex_Pr ! I added an extra right bracket to lines 32, 38 & 44.

    After I click play the error comes up "The constructor "Movie(ThisWork, int)" does not exist.

    I am quite new to processing so I'm wondering if this is because I haven't yet put the video files into the sketch?

    Also do you know if there's similiar codes out there that does the same thing as this code does?

    Thank you again. :)

  • edited January 2016

    A very nasty bug that time to time shows up is saving the sketch using the same name as another class.

  • Sorry, I'm not sure what you mean by "using the same name as another class". I'm a noob when it comes to processing.

    Thanks :)

  • The error comes up because instead of a string you give an int to Movie(parent, filename)

    If the name of the file is a number you need to convert the int(random()) to a String

    This is easily done by replacing myMovie = new Movie(this, int(random(1, 3)); to myMovie = new Movie(this, ""+int(random(1, 3));

  • edited January 2016

    Thank you Alex, that seemed to work. However now there is an error on line 24

    image(myMovie, 0, 0, width, height);

    with NullPointerException

    is this something to do with the size of the video it is trying to load?

  • edited January 2016

    That has to do with the fact that you access myMovie without it having a value. You should edit the code so that image(); command is executed only if you have pressed a button, like this:

      import processing.video.*;
    
      boolean valid=false; 
      String[] one = {
        "ag1.mov", "ag2.mov", "ag3.mov", "am1.mov", "am2.mov", "am3.mov",
        "tran1.mov", "tran2.mov", "tran3.mov"
      };
    
    
      Movie myMovie;
    
      int a = 0;
      float md = 0;
      float mt = 0;
    
      void setup()
      {
        size(400, 400, P2D);
      }
    
    
      void draw()
      {
        if (valid){
          image(myMovie, 0, 0, width, height);
        }
    
      }
    
      void keyPressed()
      {
      if (key == 'a' || key == 'A') 
        {
          valid=true;
          myMovie = new Movie(this, ""+int(random(1, 3)));
          myMovie.play();
        }
    
        else if (key == 's' || key == 'S')
        {
          valid=true;
          myMovie = new Movie(this, ""+int(random(4, 6)));
          myMovie.play();
        }
    
        else if (key == 'd' || key == 'D')
        {
          valid=true;
          myMovie = new Movie(this, ""+int(random(7, 9)));
          myMovie.play();
        }
    
        else
        {
          myMovie.stop();
        }
      }
    
  • This got me further. So now my error is now on line 35 "Could not load movie file 1"

    import processing.video.*;
    
    boolean valid=false;
    String[] one = {
      "1.mp4", "2.mp4", "3.mov", "4.mov", "5.mov", "6.mov",
      "7.mov", "8.mov", "9.mov"
    };
    
    
    Movie myMovie;
    
    int a = 0;
    float md = 0;
    float mt = 0;
    
    void setup()
    {
      size(400, 400, P2D);
    }
    
    
    void draw()
    {
      if (valid){
        image(myMovie, 0, 0, width, height);
      }
    
    }
    
    void keyPressed()
    {
    if (key == 'a' || key == 'A')
      {
        valid=true;
        myMovie = new Movie(this, ""+int(random(1, 3)));
        myMovie.play();
      }
    
      else if (key == 's' || key == 'S')
      {
        valid=true;
        myMovie = new Movie(this, ""+int(random(4, 6)));
        myMovie.play();
      }
    
      else if (key == 'd' || key == 'D')
      {
        valid=true;
        myMovie = new Movie(this, ""+int(random(7, 9)));
        myMovie.play();
      }
    
      else
      {
        myMovie.stop();
      }
    }
    

    the file names are exactly the same as they are in the sketch, I apologise for the amount of questions I'm asking here but I really appreciate your help. :)

  • What type is your file, .mov or something else? Is the video located in the sketch's data folder?

    In the IDE go to "Sketch" select "Add file..." and add the movie file you want, see if that works

  • There's only three actual video files in the sketch at the moment which is 1.mp4, 2.mp4 and 3.mov all three are in the sketchbook folder under data (assuming the sketchbook folder is the file that saves as the same name as the sketch with a data folder inside) and I tried replacing each video by going to "Sketch" select and "Add file".

  • Try playing 3.mov to check whether the filetype is the problem

  • Tried each file individually in the sketch and it still comes up with the error "Could not load movie file 3" I'm not sure what the problem is

  • (Deleted duplicate question)

  • It seems that I have managed to get the code to call a video and play it however it only plays sounds and the rest of the screen is white for each video and when I press "A" to go onto the next video they overlay each other and don't stop playing.

    import processing.video.*;
    
    boolean valid=false;
    String[] one = {
      "1.mp4", "2.mp4", "3.mov", "4.mov", "5.mov", "6.mov",
      "7.mov", "8.mov", "9.mov"
    };
    
    
    Movie myMovie;
    
    int a = 0;
    float md = 0;
    float mt = 0;
    
    void setup()
    {
      size(400, 400, P2D);
    }
    
    
    void draw()
    {
      if (valid){
        image(myMovie, 0, 0, width, height);
      }
    
    }
    
    void keyPressed()
    {
    if (key == 'a' || key == 'A')
      {
        valid=true;
        myMovie = new Movie(this, one[int(random(1, 3))]);
        myMovie.play();
      }
    
      else if (key == 's' || key == 'S')
      {
        valid=true;
        myMovie = new Movie(this, ""+int(random(4, 6)));
        myMovie.play();
      }
    
      else if (key == 'd' || key == 'D')
      {
        valid=true;
        myMovie = new Movie(this, ""+int(random(7, 9)));
        myMovie.play();
      }
    
      else
      {
        myMovie.stop();
      }
    }
    
  • #35 myMovie = new Movie(this, int(random(1, 3))+".mp4");

    and Add

    void movieEvent(Movie m) {
      m.read();
    }
    
  • Int(random(1,3)) -> 1 or 2 not 3

  • Thank you! this worked perfectly.

    I appreciate everyone helping out with this. You're all awesome. :)

Sign In or Register to comment.