Not sure how to go about it. (play video on key press)

edited May 2016 in Library Questions

Hi,

I'm trying to figure out how I would go about creating a code that will trigger a video when I hit a certain key on the keyboard. the key doesn't have to be specific, I have found various other example codes that trigger other things when you hit a key but not ones that integrate a video. Any help would be greatly appreciated! Thank you.

Tagged:

Answers

  • edited April 2016

    I don't know, try something like this

    import processing.video.*;
    Movie myMovie;
    boolean playing = false;
    
    void setup() {
      size(200, 200);
      myMovie = new Movie(this, "totoro.mov");
      myMovie.loop();
      myMovie.pause();
    }
    
    void draw() {
      tint(255, 20);
      image(myMovie, mouseX, mouseY);
    }
    
    void keyPressed(){
    if (playing){
    myMovie.pause();
    playing = false;
    } else {
    myMovie.play();
      }
    }
    
    void movieEvent(Movie m) {
      m.read();
    }
    
  • So this code didn't show any errors, but when I run it the widow pops up and a press a key and no video plays. I made sure to replace the .mov file with mine. but I'm still at a loss as to what could be keeping this code from working... :(

  • Can't test this right now. But maybe try commenting out myMovie.pause(); in setup. You will also need to adjust keyPressed() - as the boolean value 'playing' is set to false when the key is first pressed, but it is never again to be true.

    void keyPressed(){
    if (playing){
    myMovie.pause();
    playing = false;
    } else {
    myMovie.play();
    playing = true; //added
      }
    }
    

    You might want to also just try the example at https://processing.org/reference/libraries/video/Movie.html to see if you can even get video playing

Sign In or Register to comment.