How to make a video stop playing and screen++;

edited May 2016 in Library Questions

Hi guys, I have a basic set up of an animation storyline in which when the user clicks the mouse or does certain interactions, it then runs the next 'screen' or next animation. The issue I'm having is that on screen 5 a click of the mouse plays a video I made in after effects. However, this video then stops on the last frame and stays. I cannot work out how to 'screen++' after the video stops. I have tried duration, millis, etc. and nothing seems to be working. Could somebody please shed some light on what might be going on, or how I could achieve this?

import processing.video.*;
Movie myMovie;

Cell[] cells= new Cell[1000];

float x, y;
PFont Baskerville;
int screen=1;
int drawRandomLines = 0;
int ellipseSize = 0;
int totalCells = 0;

void setup () {
  size(1024, 768);
  smooth(3);
  noStroke();
  Baskerville = createFont("Baskerville", 30);
  textFont(Baskerville);
  textAlign(CENTER);
  noStroke();
  x = width/2;
  y = 0;
  myMovie = new Movie(this, "dominant_species.mov");
  //myMovie.play();
}

void draw () {

  if (screen==1) {
    background(4, 16, 36);
    fill(255, 219, 157);
    noStroke();
    //draw first screen
    ellipse(512, 384, 16, 16);
    text("Here is a cell.", width/2, height/2-40);

    // } if (y >= 384) {

    //y = height/2;

    text("Here is a cell.", width/2, height/2-40);
  } else if (screen==2) {
    background(4, 16, 36);

    fill(255, 219, 157, 20);
    rect(mouseX, 0, -mouseX, 768);
    fill(255, 219, 157);
    text("One of millions in the body.", width/2, height/2-40);

    cells[totalCells] = new Cell();

    totalCells ++ ;

    if (totalCells >= cells.length) {
      totalCells = 0;
    }

    for (int i = 0; i < totalCells; i++) {
      cells[i].move();
      cells[i].display();
    }

    if (mouseX >= 900) {
      screen++;
    }

    if (mouseY < 10 ) {
      screen++; //add one onto screen
    }
  } else if (screen==3) {
    background(255, 219, 157);
    //background(4,16,36);
    //draw third screen
    //testing to see if the mouse is inside a circle
    fill(4, 16, 36);
    text("Throughout our daily lives...", width/2, height/2-40);
  } else if (screen==4) {
    background(255, 219, 157);
    noStroke();

    text("our cells duplicate in order to heal and develop.", width/2, height/2+200);


    fill(4, 16, 36);
    ellipse(width/2-40, height/2-40, ellipseSize, ellipseSize);
    ellipse(width/2+40, height/2+40, ellipseSize, ellipseSize);
  } else if (screen==5) {
    background(4, 16, 36);
    noStroke();

    fill(255, 219, 157);
    text("That's how we've gone from a single celled organism...", width/2, height/2-20);
    image(myMovie, 0, 0);

    fill(4, 16, 36);
    ellipse(width/2-40, height/2-40, ellipseSize, ellipseSize);
    ellipse(width/2+40, height/2+40, ellipseSize, ellipseSize);
    //draw fifth screen
    //image(myMovie, 0, 0);
  }
}

//called only once when the user presses the mouse
void mousePressed () {
  if (screen==1) {
    //testing for a button notice it is the same bounds as the
    //rect we are drawing in the test for screen==1 inside draw
    //you could just write 170 instead of 130+40 but I left this
    //here so you can see how the test values relate to the rect coordinates
    float d = dist(mouseX, mouseY, 512, 384);

    if (d<20) {
      screen++;
      //myMovie.play();
    }
  } else if (screen==5) {

    myMovie.play();
  } else if (screen==3) {
    screen++;
  }
}


//called whenever the mouse is movoed
void mouseMoved () {
  if (screen == 4) {
    ellipseSize=ellipseSize+5; 
    if (ellipseSize > width) {
      println("threshold");
      //take us back to the beginning
      //reset all of our variables
      //screen=1;
      drawRandomLines = 0;
      ellipseSize = 0;
      screen++;
    }
  } else if (screen == 6) {
    //take a look inside the screen==5 inside draw
    //ellipseSize++; 
    //if (ellipseSize > width) {
    //println("threshold");
    //take us back to the beginning
    //reset all of our variables
    //screen=1;
    //drawRandomLines = 0;
    //ellipseSize = 0;
  }
}


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


//NEW TAB__ CELL CLASS

class Cell {

  float x, y;   // Variables for location of raindrop
  float speed; // Speed of raindrop
  color c;
  float r;     // Radius of raindrop

  Cell() {
    r = 8;                 // All raindrops are the same size
    x = random(mouseX);     // Start with a random x location
    y = -r*4;              // Start a little above the window
    speed = random(1, 5);   // Pick a random speed
    c = color(255,219,157); // Color
  }

  // Move the raindrop down
  void move() {
    // Increment by speed
    y += speed;
  }

  // Check if it hits the bottom
  boolean reachedBottom() {
    // If we go a little beyond the bottom
    if (y > height + r*4) { 
      return true;
    } else {
      return false;
    }
  }

  // Display the raindrop
  void display() {
    // Display the drop
    fill(c);
    noStroke();
    ellipse(x, y, r*2, r*2);
  }

}
`

Answers

Sign In or Register to comment.