Movie begin and end events

Hello I'm using the Movie class and I'm wondinering if there is some events when the movie starts (dunring the loop) to trigger some events and when the movie stops (at the end) to launch the next movie in a playlist or trigger other events Does these events exists ? or should I use duration() and time() to trigger them myself ? Thanks !

Answers

  • edited February 4 Answer ✓

    Class Movie internally invokes its protected method eosEvent() when it gets an endOfStream() event.
    This opens up to us a window of opportunity to @Override it when instantiating Movie:

    /**
     * Hacked Movie EoS Event (v1.03)
     * by GoToLoop (2016-Feb-18)
     *
     * Forum.Processing.org/two/discussion/14990/movie-begin-and-end-events#Item_1
     *
     * Forum.Processing.org/two/discussion/26225/
     * movie-duration-always-returns-0-0-framerate-
     * and-speed-do-not-seem-to-affect-playback
     */
    
    import processing.video.Movie;
    
    Movie vid;
    boolean ended;
    
    void setup() {
      frameRate(30);
      textSize(050);
      textAlign(CENTER, BASELINE);
      fill(#FFFF00);
    
      vid = new Movie(this, "transit.mov") {
        @ Override public void eosEvent() {
          super.eosEvent();
          myEoS();
        }
      };
    
      vid.play();
      while (vid.width == 0 | vid.height == 0)  delay(10);
    
      surface.setSize(vid.width, vid.height); // P3
      //size(vid.width, vid.height); // P2
    }
    
    void draw() {
      if (!ended)  background(vid);
      else {
        background((color) random(#000000));
        text("Playback has finished!", width>>1, height>>1);
      }
    }
    
    void movieEvent(final Movie m) {
      m.read();
    }
    
    void myEoS() {
      ended = true;
      frameRate(1);
    }
    
  • Thanks a lot ! It works !

Sign In or Register to comment.