We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Movies Handler (Read 429 times)
Movies Handler
Feb 24th, 2008, 1:48am
 
Hello everybody.

I'm working on a code that would be able to handle the loading of different movies according to the keystroke being pressed.
Initially i was repeating the "new Movie" instruction every time a key was pressed. Then i noticed that after a while the applet was crashing, probably because cpu was overloaded.

So... now i changed a bit the code:  with a single callback to "new Movie". The problem i'm facing now is this one now: the movies are not loaded anymore when i press a keystroke.

Any idea? :)


import processing.video.*;

Movie movieHandler, mov1, mov2, mov3, mov4, mov5, mov6;
int playing=0;

void setup() {
 size(640, 480);
 background(0);

 mov1=new Movie(this,"1.mov");
 mov2=new Movie(this,"2.mov");
 mov3=new Movie(this,"3.mov");
 mov4=new Movie(this,"4.mov");
 mov5=new Movie(this,"5.mov");
 mov6=new Movie(this,"6.mov");

 movieHandler = mov6;
 movieHandler.loop();
}

void draw() {
 background(0);
 image(movieHandler, 0, 0);
}

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

void keyReleased() {
 playing=1;
 movieHandler.stop();
 switch(key){
 case '1':
   movieHandler = mov1;
   break;

 case '2':
   movieHandler = mov2;
   break;

 case '3':
   movieHandler = mov3;
   break;

 case '4':
   movieHandler = mov4;
   break;

 case '5':
   movieHandler = mov5;
   break;
 }
 movieHandler.play();
}
Re: Movies Handler
Reply #1 - Feb 27th, 2008, 1:06am
 
ok, finally I think to have obtained what I was looking for..
here I share my crafty solution...

import processing.video.*;

Movie movieHandler, mov1, mov2, mov3, mov4, mov5, mov6;
int playing=0;

void setup() {
 size(640,480);
 frameRate(60);

 mov1 = new Movie(this, "1.mov");
 mov2 = new Movie(this, "2.mov");
 mov3 = new Movie(this, "3.mov");
 mov4 = new Movie(this, "4.mov");
 mov5 = new Movie(this, "5.mov");
 mov6 = new Movie(this, "6.mov");

 // mov6 = default movie to be played when no interaction occurs
 movieHandler=mov6;
 movieHandler.loop();
}

void draw(){
 background(0);
 // if a selected movie playing...
 if(playing==1){
   float md = movieHandler.duration();
   float mt = movieHandler.time();
  // if the selected movie has came to his end...
   if(mt >= md) {
    //... restore the default movie
     movieHandler.loop();
     playing=0;
   }
 }
 image(movieHandler, 0, 40);
}

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

void keyReleased() {
 // set the flag=1.. the selected movie is playing. stop the default one.
 playing=1;
 movieHandler.stop();

 switch(key){
 case '1':
   movieHandler = mov1;
   break;

 case '2':
   movieHandler = mov2;
   break;

 case '3':
   movieHandler = mov3;
   break;

 case '4':
   movieHandler = mov4;
   break;

 case '5':
   movieHandler = mov5;
   break;
 }

 // rewind & play
 movieHandler.jump(0);
 movieHandler.play();
}
Page Index Toggle Pages: 1