Help needed to code videos play with processing by receiving data from Arduino

hello,

and welcome to the forum!

Great to have you here!

Essentially, you have 2 videos.

You load both in setup(). Good. (Not sure, if mp4 are ok, did you test?)

Now to your problem.

In my understanding you need a variable boolean useImageMovie (or whatever name) that indicates what to play.

This:

should be

if (val <= THRESHOLD) { //If the sensor detect object at less 10cm
  sound.stop();
  video.play();
  useImageMovie= true; 
 }

if(useImageMovie) {
  image(video,0,0);
}
else {
  image(sound,0,0);
}

Because, when you say image(video,0,0); in the first if-clause it will only play during the if (val <= THRESHOLD) and not to its end.

More

when video is over, set useImageMovie to false:

useImageMovie = false;

Declaration

declare boolean useImageMovie = false; before setup()

I hope this helps!

Warm regards,

Chrisir