We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone, a newbie question here. I´m trying to select video files that will play in a random sequence. Every time I replay the sketch I see a new video, but does anyone know how to get them to play in sequence without refreshing the sketch? I´m probably missing something obvious here, grateful for any help!
import processing.video.*;
String[]vid = {"action1.mp4", "action2.mp4", "action3.mp4", "action4.mp4", "action5.mp4", "action6.mp4"};
Movie movie;
void setup() {
size(480, 270);
background (255);
frameRate(30);
movie = new Movie(this, vid[int(random(1, 6))]);
movie.loop();
}
void movieEvent(Movie m) {
m.read();
}
void draw() {
image(movie, 0, 0 );
}
Answers
random(1, 6)
gives you a number from 1 to 5, inclusive. You should use instead eitherrandom(6)
orrandom(0,6)
which they are equivalent. You need to consider the position 0 as well since array indices start at zero and not at 1.Now, you generate a new sequence of random numbers every time you run this sketch. If you do not want that, then you could just not use random and instead, randomize the entrance of filenames manually.
For playing videos sequentially, check this: https://forum.processing.org/two/discussion/23419/video-play-random-video-sequence#latest
Kf
Thanks for your help krafjer! I changed the code to
random(6)
, to include all of the videos. It seems like my problem still lingers though; when I run the sketch only one random number is generated, instead of a sequence of numbers. When you write about randomizing the entrance of filenames manually, do you mean by using some input? Thanks for the link, I will give it a go.@twip -- see this recent discussion of random ordering and shuffling:
Instead of
movie = new Movie(this, vid[int(random(6))]);
you could do:Kf
Thanks jeremydouglass, I´ll check that out!
Thanks again kfrajer for your input! I tried the code out, but unfortunately won´t get it to work. One video plays, but this time it´s the same every time I replay the sketch.
Ok, for this, you need to check the first link I provided, my post on July 14th. Give it a try and if you are stuck, just reply below. start by providing only three video names. If you want 5 video, it is a small easy change. What is important is to have the sketch running. When it is running, you need to use the keys:
a s d
to make each section play a video.Kf
I´ll give it a try! Thanks kfrajer.