How to display a blank frame when a video is paused

edited May 2014 in How To...

Hi, so right now I am playing a video via the usual method of

import processing.video.*;
Movie myMovie;

void setup() {
  size(1920, 1080);
  background(0);
  myMovie = new Movie(this, "movie.mp4");
  myMovie.loop();
}

and then pausing it with mouse clicks like so

void mousePressed() {
   myMovie.pause();
   background(249, 227, 162);  
}

How can I make it display the background or a jpeg while the video is paused?

Tagged:

Answers

  • edited May 2014 Answer ✓

    Taking a look at its source code @ "Movie.java", we can see these 3 protected fields:

    protected boolean playing = false;
    protected boolean paused  = false;
    protected boolean repeat  = false;
    

    Dunno why but that library doesn't provide us any methods to read those important informations! :-w

    • For 1 Movie, the simplest solution is to declare our own boolean flag field.
    • Then couple loop() & pause() actions together w/ that flag.
    • This way it's as simple as checking that flag in order to know whether the Movie is paused or not! :bz

    So here's a sample of the idea:

    // forum.processing.org/two/discussion/5043/
    // how-to-display-a-blank-frame-when-a-video-is-paused
    
    import processing.video.*;
    
    Movie myMovie;
    boolean isPaused;
    
    void playMovie() {
      myMovie.play();
      isPaused = false;
    }
    
    void pauseMovie() {
      myMovie.pause();
      isPaused = true;
    }
    
    void switchMovie() {
      if (isPaused = !isPaused)  myMovie.pause();
      else                       myMovie.play();
    }
    

    P.S.: The other way is hack the Movie class by extending it. Then create a method to spit out current paused field's state! ;-)

  • Thank you. That was very helpful. However, I still have have trouble displaying the image when it's paused. Right now I'm using

    void draw() {
      if (isPaused) {
        image(blank, 0, 0);
      }
      else {
      image(myMovie, 0, 0);
      }
    }
    

    but it just flashes the background color then goes back to showing the paused movie frame.

  • Nevermind. I forgot to place the isPaused variable in the functions that actually pause the movie. Thanks again!

  • edited May 2014 Answer ✓

    Glad it's finally work! As another extra, a shorter version for which PImage to display: :ar!
    set(0, 0, isPaused? blank : myMovie);

    Or even w/ background() if both PImage objects got exactly the same width & height as the canvas': :P
    background(isPaused? blank : myMovie);

Sign In or Register to comment.