Fairly new to Processing, and could use some help and input. I'm working on a project in which it's necessary to control at least two video clips. I've been using the Processing Movie reference and also this tutorial from Elie Zananiri.
The basic gist is, one video should play constantly on a loop, until a switch (like a key press) makes a second video play, and once that video is done playing, the first video should return to automatic loop, until that switch goes off again.
Through these resources I've been able to set up a basic code, where pressing a key ('1') makes one video loop, pressing another ('2') makes that loop stop and play a second video. That's where I run into problems, so here are my questions:
- Pressing '2' again does not make the second video play again. Once it's played one time, it can't be played a second or third. Is there a workaround?
- The videos load in layers. Even though I can't make the second video play a second time, I can get the first video to begin looping again after pressing '1'. However, because they load in layers, it is covered by the second, unplayable video. How do I get it to play on top, or to not load in layers?
- I need to find a way to make the first video play as soon as the second video is finished, but all the commands within the Processing reference only allow them to play simultaneously. I have considered using a timer for this but am not sure how to proceed or if that's even the right answer. I've had friends and mentors suggest state machines, but that seems like it might be a little complicated for something that ought to be simple.
- Do if/then statements exist within Processing? The book I have on the subject only covers if/else statements and a Google search turned up no answers, so I'm thinking they might not.
Code:
- import processing.video.*;
- Movie dobBark; // adds variable for Doberman Bark video
- Movie dobStop; // adds variable for Doberman Stop video
- void setup() {
- size(480, 272); // defines size of the video window -- needs tweeking.
- dobBark = new Movie(this, "dobBark.m4v"); // loads Doberman Bark vid.
- dobStop = new Movie(this, "dobStop.m4v"); // loads Doberman Stop vid.
- }
- void draw() {
- image(dobBark, 0, 0); // without this code, none of the videos will show up
- image(dobStop, 0, 0);
- }
- void movieEvent(Movie m) {
- m.read(); // not really sure what this does but you need it.
- }
- void keyPressed() {
- if(key=='1'){
- dobBark.loop(); // if you press the 1 key, Doberman Bark video will loop.
- }
- if(key=='2') {
- dobBark.stop(); // if you press the 2 key, the Doberman Bark video will stop
- dobStop.play(); // and the Doberman Stop video will play only once.
- }
- }