We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone! I have a pretty simple question to ask about a code I'm writing however I can't get my head around it, just wondering if anyone has an answer! :)
The code is designed so when you press one of the keys 'W' 'E' 'R' 'T' or 'Y' a background video will change to one of 5 files. This code seems to be working fine however, I'm trying to also create 15 other smaller videos split into groups of 3 to randomly appear one at a time when one of the keys are pressed. (so each key has 3 videos to randomly be picked from each time it is pressed).
For example, user presses the 'W' key and the background video changes and a random smaller video is put on top of the background from one of the groups of 3 assigned for that letter.
If anyone out there has a possible answer this, i would be incredibly grateful!
thanks.
import processing.video.*;
import java.util.*;
import processing.video.*;
Movie movie;
Movie movie2;
// Add More Videos here
String[] videos = {"Down trans.mp4", "Down trans.mp4"};
int currentVideo = 0;
void setup() {
size(640, 360);
background(0);
// Load and play the video in a loop
movie = new Movie(this, videos[currentVideo]);
movie.loop();
movie2 = new Movie(this, videos[currentVideo+1]);
movie2.loop();
movie = new Movie(this, videos[currentVideo+2]);
movie.loop();
}
void movieEvent(Movie m) {
m.read();
}
void draw() {
//if (movie.available() == true) {
// movie.read();
//}
image(movie, 0, 0, width, height);
tint(255, 127); // Display at half opacity
image(movie2, 10, 10, width, height);
noTint();
}
void keyPressed(){
if (key == 'Q'){
movie.stop();
currentVideo++;
movie = new Movie(this, videos[currentVideo]);
movie.loop();
}
void pickRandomVideoIndex() {
if (movies.length <= 1) return;
movies[index].pause(); // pause current video.
int rnd; // keep picking a new index till got a diff. 1:
while ( (rnd = (int) random(movies.length)) == index );
// assign newly picked random value to index:
movies[index = rnd].loop(); // and start playing it.
}
if (key == 'W'){
movie.stop();
currentVideo--;
movie = new Movie(this, videos[currentVideo+1]);
movie.loop();
}
if (key == 'E'){
movie.stop();
currentVideo--;
movie = new Movie(this, videos[currentVideo+2]);
movie.loop();
}
if (key == 'R'){
movie.stop();
currentVideo--;
movie = new Movie(this, videos[currentVideo+3]);
movie.loop();
}
if (key == 'T'){
movie.stop();
currentVideo--;
movie = new Movie(this, videos[currentVideo+4]);
movie.loop();
}
if (key == 'Y'){
movie.stop();
currentVideo--;
movie = new Movie(this, videos[currentVideo+5]);
movie.loop();
}
}
Answers
--
ok
go back, edit your post
format the code right
empty line before and after the code
highlight entire code
hit ctrl-o
Thanks Chrisir, didn't know about this. I added the code to my first comment. I'll keep keep that in mind from now on! :)