I would like to play full movie every time when I touch yellow rectangle

edited December 2017 in Library Questions

I have figured out how to play and stop a movie.

Here I would like to know 2 things.

  1. I dont want screen to become black when I stop a movie.

  2. I would like to play full movie every time when I touch yellow rectangle. In other words, I dont want to stop a movie in a middle of video.

Thank You, Arigato m()m

import processing.video.*; 
Movie movie;

void setup() {
  colorMode(HSB, 360, 100, 100); 
  size(1280, 720);
  movie = new Movie( this, "movie.avi");
  frameRate(60);
}

void ellipseFront() {
  fill(0, 100, 100);
  ellipse(width*1/3, height/2, 100, 100);
}

void ellipseBack() {
  fill(120, 100, 100);
  ellipse(width*2/3, height/2, 100, 100);
}

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

void playMovie() {
  fill(60, 100, 100);
  rect(100, 100, 200, 200); //yellow rectangle
  image( movie, 0, 0, width, height);
  if (mouseX > 100 && mouseX <300 && mouseY > 100 && mouseY <300) {  //when I touch yellow rect play movie
    movie.play();
  } else {
    movie.stop();
  }
}

void draw() {
  background(360);
  ellipseBack();
  playMovie();
  ellipseFront();
}
Tagged:

Answers

  • The best advice we can give you is to break your problem down into smaller pieces.

    You've already split it into two separate steps, and that's great. Now you should create small example programs that test out each step by themselves.

    What exactly do you mean when you say you don't want the screen to go to black when you stop the movie? Create an example sketch that deals only with this step.

    Separate from that, create another example sketch that shows a yellow button. Print something to the console when you detect a click on the button. Iterate on that until you have a more complete program.

    But just looking at the code you have, it looks like you want to have a check inside the button click: if the movie is already playing, then don't stop it, right? What happens when you try that?

  • Answer ✓

    @KevinWorkman

    Thank you for your advices! arigato!

    It shows "black" screen for a moment when I start playing a movie and when I stop a movie.

    I have figured out how to play full movie every time when I wanted.

    This Japanese web site helped me how to play movie in Processing. http://mslabo.sakura.ne.jp/WordPress/make/processing

    Here is a code I wrote, based on the web site above.

    
    import processing.video.*;
    //import org.gstreamer.elements.*;
    
    Movie     movie;             //Movie instance 
    //PlayBin2  bin2;              //you can use this to get moviePlaying
    
    void setup() {
      size(1280, 720);
      movie = new Movie( this, "movie.avi"); 
      //PlayBin2
      //bin2 = movie.playbin;
    }
    
    void draw() {
      colorMode(HSB, 360, 100, 100);
      background(360);
      movie.play();
      // hide black screen at the first, and at the end.
      if (movie.time()>0.1 && movie.time()<9.5) { 
        image(movie, 0, 0, width, height);
      }
    }
    
    void movieEvent( Movie m ) {
      m.read();
    }
    
    void mouseClicked() {
      if ( mouseX < 0 || mouseX > width ||
        mouseY < 0 || mouseY > height ) {
        return;
      }
      movie.stop();
    }
    
    
Sign In or Register to comment.