We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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();
}
}
Answers
Line #32 -> Missing an extra closing parens. Tip: Hit CTRL+T inside PDE. O:-)
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.
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. :)
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));
tomyMovie = new Movie(this, ""+int(random(1, 3));
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?
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:
This got me further. So now my error is now on line 35 "Could not load movie file 1"
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.
#35 myMovie = new Movie(this, int(random(1, 3))+".mp4");
and Add
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. :)