How can I get multiple videos to play one after another and triggered by specific keys?

edited April 2017 in Library Questions

Hi. I'm quite new to Processing and this is my first time working with it in about a year.

I'm trying to make a program that will play one of 6 videos based on which key is pressed. I'm using a Makey Makey so the keys would be space, mouse click, up, down, left, and right.

I've been exploring all over the internet for tips to get me to where I am now and I have tried a number of methods some of which have sort of worked.

At the moment the videos sort of work, but don't fit into the screen. The first video plays if I hold down the up, down, left or right keys, but it is really glitchy. Pressing the space bar or mouse clicking doesn't seem to have any effect.

I've also tried using the external library RemoteVLC, but haven't had any luck with it yet.

Does anyone have any suggestions about the easiest way to go about this that will work?

Here's my code:

import processing.video.*;
Movie myMovie1, myMovie2, myMovie3, myMovie4, myMovie5, myMovie6;

boolean playMovie1=true;
boolean playMovie2=false;
boolean playMovie3=false;
boolean playMovie4=false;
boolean playMovie5=false;
boolean playMovie6=false;

void setup(){
  size(1080,920);
  myMovie1 = new Movie(this, "InABoxScene1.mp4");
  myMovie2 = new Movie(this, "InABoxScene2.mp4");
  myMovie3 = new Movie(this, "InABoxScene3.mp4");
  myMovie4 = new Movie(this, "InABoxScene4.mp4");
  myMovie5 = new Movie(this, "InABoxScene5.mp4");
  myMovie6 = new Movie(this, "InABoxScene6.mp4");
}

void keyPressed(){  
if(key==CODED && playMovie1==true){
  //if SPACE pressed
  if(keyCode == ' ');
  myMovie1.play();
  image(myMovie1,0,0);
  //ellipse(200,100,25,25);
  //fill(0,0,0);
  if(myMovie1.time()>=myMovie1.duration()){
    myMovie1.stop();
    playMovie1=false;
    playMovie2=true;
  }
}

if(key==CODED && playMovie2==true){
  if(keyCode == UP);
  myMovie2.play();
  image(myMovie2,0,0);
  //rect(400,300,50,50);
  //fill(255,0,0);
  if(myMovie2.time()>=myMovie2.duration()){
    myMovie2.stop();
    playMovie2=false;
    playMovie3=true;
  }
}

if(key==CODED && playMovie3==true){
   if(keyCode == DOWN);
   myMovie3.play();
   image(myMovie3,0,0);
   if(myMovie3.time()>=myMovie3.duration()){
     myMovie3.stop();
     playMovie3=false;
     playMovie4=true;
  }
}

if(key==CODED && playMovie4==true){
  if(keyCode == LEFT);
   myMovie4.play();
  image(myMovie4,0,0);
  if(myMovie4.time()>=myMovie4.duration()){
     myMovie4.stop();
     playMovie4=false;
     playMovie5=true;
  }
}

if(key==CODED && playMovie5==true){
  if(keyCode == RIGHT);
   myMovie5.play();
  image(myMovie5,0,0);
  if(myMovie5.time()>=myMovie5.duration()){
     myMovie5.stop();
     playMovie5=false;
     playMovie6=true;
  }
}
}

void mousePressed(){
if(playMovie6==true){
   myMovie6.play();
  image(myMovie6,0,0);
  //ellipse(100,300,100,100);
  //fill(0,0,0);
  if(myMovie6.time()>=myMovie6.duration()){
     myMovie6.stop();
     playMovie6=false;
  }
}
}

void draw(){
  background(0);
}

void movieEvent(Movie m){
  m.read();
}

Any help would be appreciated! Thanks!

Tagged:

Answers

  • hey!

    I haven't tried the code. but first you need to draw the movie in void draw() with image().

    I have this code, you can try it, it load three videos and plays them with three different keys, also it tells you when the video is finish. you can use this to automatic start a random video from the array.

    import processing.video.*;

    Movie myMovie[];
    float t0;
    float t;
    int index = 0;
    
    void setup() {
      size(720, 576);
    
      myMovie = new Movie[3];
    
      myMovie[0]  = new Movie(this, "station.mov");
      myMovie[1]  = new Movie(this, "station.mov");
      myMovie[2]  = new Movie(this, "transit.mov");
    
      myMovie[0].pause();
      myMovie[1].pause();
      myMovie[2].pause();
    }
    
    
    void draw() {
      background(0);
    
      if (myMovie[index].available() ) {
        myMovie[index].read();
      }
      image(myMovie[index], 0, 0);
    
      if (t > myMovie[index].duration() + t0) {
        println("finished! "+index);
      }
    
      t  = millis()/1000;
    }
    
    void keyPressed() {
      if (key == 'a') {
        myMovie[0].play();
        index = 0;
        t0 = millis()/1000;
      }
    
      if (key == 's') {
        myMovie[1].play();
        index = 1;
        t0 = millis()/1000;
      }
      if (key == 'd') {
        myMovie[2].play();
        index = 2;
        t0 = millis()/1000;
      }
    }
    

    thomas

Sign In or Register to comment.