Play and replay the video after few second of the playing time message.

edited February 2018 in Library Questions

Hello

I was trying to make a code for playing my project. But I couldn't figure out how to make the same video play and after finished showing few second (maybe 5 seconds) of how many times video played. and again playing the video.

  1. after the finished video, then showing the message
  2. the message counting how many times played.
  3. 5 sec after automatically play again.

It could be a very obvious question, but few days of searching, I still couldn't find the solution...

please anyone can advise on this problem?

import processing.video.Movie;

Movie vid;
boolean ended;

void setup() {
  frameRate(30);
  textSize(050);
  textAlign(CENTER, BASELINE);
  fill(0);

  vid = new Movie(this, "StudioOutside.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 {
    if (key == ' ' || key == ' ') {
      keyPressed = true;
    if (keyPressed == true) {
     background(vid);
     vid.play();
    }
      } else {
    vid.stop();
    background(255);
    text("Playback has finished!", width>>1, height>>1);
  }
  }
}

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

void myEoS() {
  ended = true;
  frameRate(1);
}

Answers

  • keyPressed = true;
    

    keyPressed is a reserved variable. probably best to use another name.

    keyPressed = true;
    if (keyPressed == true) {
    

    you know the condition is true, you've just set it to true

    width>>1
    

    what's this do?

    you have to rewind() a video before playing it again, it's like a tape.

  • I couldn't figure out how to make the same video play and after finished showing few second

    Check the following modifications.

    Kf

    import processing.video.Movie;
    
    final int IDLE=0;
    final int PLAYING=1;
    final int ENDED=2;
    
    final int WAIT_TIME=5000;  //5sec
    
    Movie vid;
    int state=IDLE;
    int ctr=0;
    int targetTime=0;
    
    void setup() {
      frameRate(30);
      textSize(050);
      textAlign(CENTER, BASELINE);
      fill(0);
    
      vid = new Movie(this, "processing-movie.mp4") {
        @ Override public void eosEvent() {
          super.eosEvent();
          myEoS();
        }
      };
    
      vid.play();
      while (vid.width == 0 | vid.height == 0)  delay(10);
    
      surface.setSize(vid.width, vid.height); 
    }
    
    void draw() {
      background(0);
    
      if (state==PLAYING) {
        image(vid, 0, 0);
      } else if (state==ENDED) {
        //vid.stop();
        background(255);
        text("Playback has finished= "+ctr+" times", width>>1, height>>1);
        if (millis()>targetTime) {
          state=IDLE;
        }
      } else if (state==IDLE) {
        vid.play();
        state=PLAYING;
      }
    }
    
    void movieEvent(final Movie m) {
      m.read();
    }
    
    void myEoS() {
      state=ENDED;
      ctr++;
      targetTime=millis()+WAIT_TIME;
      vid.stop();
    }
    
Sign In or Register to comment.