manipulate consecutive videos

edited January 2017 in Library Questions

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);
}
}
Tagged:

Answers

  • Answer ✓

    The following code is your provided code but arranged in a way that it only starts playing a movie when there is a change in val. As you have it right now, you are calling the play() function 60 times a second in your draw() function.

    The next thing that needs to be done is to detect when a movie has stopped playing in order to either play the b pair or to trigger the random choosing of the a pair in case b movie stops playing. This will be handled later or probly in another post. An idea is to use the example provided at Libraries>>Video>>Movie>>Frames.pde or duration() coupled with millis(): https://processing.org/reference/libraries/video/Movie_duration_.html. This will require its own implementation.

    I didn't run the next code so it might have bugs or it might need further modifications.

    Kf

    import processing.video.*;
    int index=0; 
    int num=3; 
    
    Movie[] moviesa=new Movie[num]; 
    Movie[] moviesb=new Movie[num];
    
    int val, pval; 
    boolean execMovie=false;
    
    void setup() {
      size(1280, 720, P2D); 
    
      for (int i=0; i<num; i++)
      {
        moviesa[i]=new Movie(this, i+"a"+".mp4");
        moviesb[i]=new Movie(this, i+"b"+".mp4");
      }
      pval=val;
    }
    
    void movieEvent(Movie movie) {
    
      if (val==0)
        moviesa[index].read();
      else
        moviesb[index].read();
    }
    
    void draw() {
      if (mouseX>width/2) {  
        val=0;
      } else {
        val=1;
      }
    
      if (val!=pval)
        execMovie=true;
    
      pval=val;
    
      if (execMovie==true) {
        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);
        }
        execMovie=false;
      }
    }
    
  • You helped me a lot. Thank you!!!

Sign In or Register to comment.