Hi. I am trying to write a sketch that manipulates two consecutive videos. When the value of val is equal to 0, video “0a.mp4” starts to play and stops at the last scene, and when val is equal to 1, video “0b.mp4” starts to play and stops at the last scene. When the value of val becomes 0 again, video “0a.mp4” starts again.
Val takes the value 0 when the mouse is on the left side of the window and 0 when it is on the right. I will change that when I will send some data from Arduino through serial port.
My problem is that when the value of val becomes again 0, I want the program to pick a random video from the String moviesa (like “5a.mp4”) and play this instead of “0a.mp4” (and then if the value of val becames 1, play “5b.mp4”).
I tried to put the command :
index=int(random(num));
between lines 43 and 44 but the program got stuck.
Thank you.
Script
import processing.video.*;
int index=0;
int num=3;
Movie[] moviesa=new Movie[num];
Movie[] moviesb=new Movie[num];
int val;
void setup() {
size(1280,720,P2D);
for (int i=0; i<num; i++)
{
moviesa[i]=new Movie(this,i+"a"+".mp4");
}
for(int k=0; k<num; k++)
{
moviesb[k]=new Movie(this,k+"b"+".mp4");
}
}
void movieEvent(Movie movie) {
for (int i=0; i<num; i++)
{
moviesa[i].read();
}
for (int k=0; k<num; k++)
{
moviesb[k].read();
}
}
void draw() {
if (mouseX>width/2)
{val=0;}
else
{val=1;}
if(val==0) {
moviesb[index].stop();
moviesa[index].play();
image(moviesa[index], 0, 0);
}
else {
moviesa[index].stop();
moviesb[index].play();
image(moviesb[index], 0, 0);
}
}