Hello! I guess my problem isn’t so hard to solve, but I really need some help with this.
I have an array of videos and I’m playing a random video everytime a key is pressed.
Now with pressing another key I want to use another function that will affect the video that is playing at this moment.
But I can’t figure out how to make it. Please help me, here is the code:
import processing.video.*;
String[] moviesNames = {
"1.MOV", "2.MOV"
};
int index = int(random(moviesNames.length));
Movie[] movies;
//Movie mov_a, mov_b, mov_c, mov_d, nowPlaying;
Boolean isPlaying = false;
void setup() {
size(displayWidth, displayHeight, P2D);
background(0);
frameRate = 30;
movies = new Movie[moviesNames.length];
for (int i = 0; i < moviesNames.length; i++) {
movies[i] = new Movie(this, moviesNames[i]);
}
}
void draw() {
background(0);
if(isPlaying){
image(movies[index], 0, 0, width, height);
}
}
void movieEvent(Movie _mov) {
_mov.read();
}
void keyPressed() {
isPlaying = true;
if ((keyPressed == true) && ((key == ‘s’) || (key == ‘S’))){
pickRandomVideoIndex();
}
if ((keyPressed == true) && ((key == ‘g’) || (key == ‘G’)))
{(random(index.duration()));
}
}
// int k = keyCode;
// if (k >= ‘A’ && k <= ‘Z’){
// pickRandomVideoIndex();
// }
//}
//void keyReleased(){
// isPlaying = false;
// movies[index].stop();
//}
void pickRandomVideoIndex() {
if (movies.length <= 1) {
return;
}
//movies[index].pause(); // pause current video.
int rnd = index; // keep picking a new index till got a diff. 1:
while ( rnd == index ){
rnd = (int) random(movies.length);
}
// assign newly picked random value to index:
index = rnd;
movies[index].loop(); // and start playing it.
}