Keypressed - Loop Video - toggle "SketchBooks" - Script

Hello everyone,
Thank you for your attention and your help.
I am starting a project with Processing (I am a novice) and I was nevertheless able to compile a script
which allows me to assign the 26 letters from my computer keyboard to a video (“keypressed”
function ).
I would like when I type for example “A” on my computer keyboard that the corresponding video “A”;
plays in loop until I choose another letter and so on …
I would like to be able to play videos in a loop and in full screen, one after the other, without
the sounds overlapping.
My problem: when I loop my videos, the sound of my video played is overlapped on the sounds of
the following video, which creates a kind of sound cacophony … as if the program keeps in memory
the current sound content ?
Did I make several mistakes when writing my program? Is there a function / solution to avoid this

I would like to create ten thematic “SketchBooks” (each one including 26 videos), and I would like to
access them via the keypad numbers (from 0 to 9).
I would like to be able to assign from 0 to 9 my thematic “SketchBook” and play for each
“SketchBook” the 26 videos corresponding to the letters of the alphabet… but also to have the
possibility of being able to go from one video to another from another “SketchBook”
For example, I would like so switch from “SketchBook” n.3 + letter A to “SketchBook” n.4 +
letter T
Below is the script that I have begun to compile : how to play the video “A” assigned to the “A”
key on my keyboard :

Script :

Movie theMov;
int VideoPlaying;

// name the “boolean” corresponding to video 1 to 26 (Vid1 to Vid26).
boolean Vid1 = false;
boolean Vid2 = false;
//up to 26

boolean isPlaying;

Movie Video1;
Movie Video2;
//up to 26

// SetUp
void setup() {
size(800, 600);

// Name the video
Video1 = new Movie(this, '''');
Video2 = new Movie(this, '''');
//up to 26 (of to

void draw() {
if (Vid1) {
image(Video1, 0, 0, width, height);
//up to 26
void movieEvent(Movie m) {;

void keyPressed() {
//If I click on A I play the video "A"
if (key == 'a') {
VideoPlaying = 1;

//up to 26
void toogle() {
if (VideoPlaying == 1)
Vid1 = true;
Vid2 = false;
Vid3 = false;
Vid4 = false;
Vid5 = false;
Vid6 = false;
Vid7 = false;
Vid8 = false;
Vid9 = false;
Vid10 = false ;
Vid11 = false;
Vid12 = false;
Vid13 = false;
Vid14 = false;
Vid15 = false ;
Vid16 = false;
Vid17 = false;
Vid18 = false ;
Vid19 = false;
Vid20 = false ;
Vid21 = false;
Vid22 = false;
Vid23 = false;
Vid24 = false;
Vid25 = false;
Vid26 = false;

// repeat up to 26 for each video "True" for the video in question, "False" for the others
1 Like

Do you ever call stop() on the current video before starting the new one?

I highly suggest looking into Arrays. Here’s a nifty tutorial:

From the sound of it, though, you’re well on your way to making this work. However, arrays are among a handful of really foundational programming concepts that will make your life easier in the future. Good luck!


Thank you very much for your help !
My script is not academic but it works :wink:
I still have the question of switching between different sketchbooks with the numeric keypad (from 0 to 9). An idea with keypressed function?
I saw a term load.path???
Thanks again Tony !

I think your 0-9 key idea is definitely possible - however, give the current state of your code (using only if-statements), is going to result in a lengthy piece of code.

That’s why I emphasized learning about arrays. Instead of keeping track of 26*10 objects (that also have to be meticulously named and remembered) you’ll be able to store everything in one nice data-structure. One other really important concept that follows Arrays is the For-Loop.

Hope that points you in the right direction!


Thank you very much for your help ! I will try to work on this track in the meantime I will create the content…