Help: How can I make this generator pause and resume between random videos?

Hi all!

I’m working on a random video generator that imitates TV with the mouseClicked to switch through the “channels”/videos. I am aiming to make it so that even if you aren’t on the “channel”, it still plays in the background and when you return to that random “channel”, you can see it. Similar to TV. How can I do this? What should I add/change in my code to make that happen?

Thanks a lot!

//video set up
Movie video;
String[]vid = {"megaman.mp4","yoshi-island.mp4", "boogerman.mp4", "medabots.mp4"};

//pointillism ellipse
int size = 34;

void setup(){
  //random movie plays
  video = new Movie(this,vid[int(random(3))]);
  //change cursor style  

void movieEvent(Movie video){;

void draw(){
  //ellipse visuals
  fill (0);
  float tiles = mouseX/2;
  float tileSize = width/tiles;
  //fixing the ellipse to fit the screen properly
  translate(tileSize/2, tileSize/2);
 //loop function for ellipses
  for (int x = 0; x < tiles; x++) {
    for (int y = 0; y < tiles; y++) {
 //size of ellipse based on color between black and white    
      color c = video.get(int(x*tileSize),int(y*tileSize));
      float size = map(brightness(c),0,255,tileSize,0);


//mouse click to randomly generate next video
  void mouseClicked(){
  video = new Movie(this, vid[int(random(vid.length))]);
  image(video, 0,0);


Hi there

If I follow you correctly you want it to be as though all the videos start playing when the sketch starts and when you switch channel you will switch to that time in the new video, eg if it’s 60s in when you switch boogerman it will show from 60s and not from beginning.

To do this as part of the channel switching you will need to factor in:

1 how long has sketch been playing?
2 how long is the video im switching to
3 has the video looped yet? (if they will loop?)
4 what time will i be at in the new video
5 jump to that point in the new video to start playback when switching

This shows you how to jump to a start time


Hi Tinkerer! This seems like the way to go but I’m still quite new to Processing and am not sure how exactly I should implement this. Currently, each video only starts playing when it is randomly selected, then it stops when I mouse click and switch the video. How do I make them all play together at the start of the sketch (like you’ve described) and how do I make it so that only one is actual visible and audible at a time?

This is all really new to me and I’d appreciate any help!

Thank you!

hi malani

i’ll keep it abit general so you can try and look up the answers yourself - this way you enjoy the puzzle and learn more

the videos dont all need to be playing - just when you switch to them you tell the new video to start playing from a later point as though it had been playing from the start of the sketch

let’s say you switch to a new video at 30 secs
in your mousepressed code you say:
play new video, start at 30 secs

then at 49 you switch again
play new video, start at 49 secs

this way it seems as though you have been playing the videos the whole time but actually you just started 30 and 49 seconds in

there is a time counter in processing called millis you can use to keep track of the time

and then feed the time (be careful of the units) in to the video start command using the jump command i linked to earlier

have a play with the example sketch in the jump page (change it for one of your own videos) mess around with the code and see what happens

I got it to work in a much easier way by actually removing the random feature, making a variable called “currentVideo = 0;” and the value of that variable updates +1 with every mouse click.

Now I have a question about how to host a Processing sketch on a webpage… I heard it is not possible if I have a loaded library (which I do… but I’ll open a new forum thread and see! :slight_smile:

Anyway, thank you for your guidance and responses.

1 Like