We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, so I have the code that follows next, what I pretend is to create a rule where if I press the key "2" it will play the video number 2 , but I don't know how to get it. I have all the videos in the same folder. The names are : video1.mp4 , video2.mp4...etc . I need a rule where I play video 2 by pressing key number 2. Please help me.
Code :
import processing.video.*;
Movie theMov;
boolean isPlaying;
boolean isLooping;
void setup() {
size(600, 300);
theMov = new Movie(this, "C:/Users/Filipe/Documents/Processing/libraries/video/video1.mp4");
theMov.loop(); //plays the movie over and over
isPlaying = true;
isLooping = true;
}
void draw() {
background(0);
image(theMov, mouseX-theMov.width/2, mouseY-theMov.height/4);
}
void movieEvent(Movie m) {
m.read();
}
void keyPressed() {
if (key == 'p') {
// toggle pausing
if (isPlaying) {
theMov.pause();
} else {
theMov.play();
}
isPlaying = !isPlaying;
} else if (key == 'l') {
// toggle looping
if (isLooping) {
theMov.noLoop();
} else {
theMov.loop();
}
isLooping = !isLooping;
} else if (key == 's') {
// stop playing
theMov.stop();
isPlaying = false;
} else if (key == 'j') {
// jump to a random time
theMov.jump(random(theMov.duration()));
}
}
Answers
You have enough sample code handy to be able to accomplish this yourself. I think what you are really missing is an understand of the process that should occur. So let's come up with a plan first.
What should happen before the sketch even starts?
You should load the first video.
You should load the second video.
You should remember that the first video is the one that will be playing first.
You should start the first video playing.
What happens when the sketch is redrawn?
What happens when a key is pressed?
If the first movie is playing and the key pressed was 2, then...
... stop playing the first movie.
... start playing the second movie.
... and remember that second movie is now the one that is playing.
I would suggest that you write a new sketch that does only the above. Use the existing sketch you have as reference - do NOT try to change it!
Once you have attempted the above steps, post the code of your attempt here for more help.
** WORKING :D**