Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

How to swap and play video files using functions

$
0
0

Hi guys, I'm having some trouble getting this interactive piece to work. I want to hover over the top left of my sketch and have Scene 1 play. Then a minute later, hover over it and have Scene 2 play and around a minute and a half later, have Scene 3 play. However, the mouseX and mouse Y commands are ignored after Scene 1 plays through and when I input a timer, it is also ignored. In my final code, each scene function will contain 7 videos, so that's why I'm using "myMovie" as my base code and swapping different movie files in. For example, I will have myMovie1, myMovie2, myMovie3, myMovie4 etc, and load Scene 1's 7 files, dispose of them, then move onto scene 2's 7 files and eventually Scene 3's.

If anyone has any advice or can test this out it would be greatly appreciated. Thanks everyone!

import processing.video.*;

Movie myMovie;

boolean mouseInCorrectLocationToPlayVideo;

boolean hasMovieEnded;

float movieEndDuration = 0.1;

int whichSceneIAmCurrentlyOn = 0;

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

loadScene1();

}

void draw(){
println(millis());

    //Checking if movie has ended.
    //If movie has not yet ended, check mouseX & Y location.
    // If mouse is in these boundaries, mouseInCorrectLocationToPlayVideo is true.
   if (hasMovieEnded == false){
      if ((mouseX < 213) && (mouseY <= 240)){
        if((mouseX > 0) && (mouseY >= 0)){

            mouseInCorrectLocationToPlayVideo = true;
         }
       }
     }

    //If mouse X & Y are not in these boundaries, print out.
     if(mouseInCorrectLocationToPlayVideo == false){
     println("not in boundaries");
   }

   //If mouse X & Y are in these boundaries, play video.
   if (mouseInCorrectLocationToPlayVideo == true) {
    myMovie.play();
    image(myMovie, 0, 0);
    //println("1:" + frameCount);

    //When movie ends, dispose of movie file from memory.
    if  ((myMovie.time() + movieEndDuration) >= myMovie.duration()){

      myMovie.dispose();
      unregisterMethod("dispose", myMovie);
      g.removeCache(myMovie);
      println("current movie finished file dumped");

      //Movie has ended.
      hasMovieEnded = true;
      //MouseX and Y are not within stated boundaries anymore.
      mouseInCorrectLocationToPlayVideo = false;

      //  if (millis() > 10*1000){ //not working
        if (whichSceneIAmCurrentlyOn == 1){
           reset();
           loadScene2();
         }
      //   }
        else if (whichSceneIAmCurrentlyOn == 2){
          reset();
          loadScene3();
        }

    }
  }
} //closes draw

void reset(){
 // mouseInCorrectLocationToPlayVideo = false; //not needed
  hasMovieEnded = false;
}

void loadScene1(){

   myMovie = new Movie(this, "tileScene1.mp4");
   whichSceneIAmCurrentlyOn = whichSceneIAmCurrentlyOn + 1;
}

void loadScene2(){

    myMovie = new Movie(this, "tileScene2.mp4");
    whichSceneIAmCurrentlyOn = whichSceneIAmCurrentlyOn + 1;
}

void loadScene3(){

    myMovie = new Movie(this, "tileScene3.mp4");
    whichSceneIAmCurrentlyOn = whichSceneIAmCurrentlyOn + 1;
}


void movieEvent(Movie m) {
   if (m == myMovie) {
    myMovie.read();
  }
}

Viewing all articles
Browse latest Browse all 2896

Trending Articles