Advertisement
hamoid

Random video player

Apr 16th, 2015
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. import processing.video.*;
  2.  
  3. Movie[] mov = new Movie[2];
  4. int current = 0;
  5.  
  6. int totalMovies = 4;
  7. // assumes 0.mp4 1.mp4 2.mp4 3.mp4
  8.  
  9. void setup() {
  10.   size(720, 480);
  11.   newRandomMovie();
  12. }
  13.  
  14. void movieEvent(Movie m) {
  15.   m.read();
  16.   if(m.time() > m.duration() - 0.5) {
  17.     m.stop();
  18.     newRandomMovie();
  19.   }
  20. }
  21.  
  22. void draw() {
  23.   image(mov[current], 0, 0, width, height);
  24. }
  25.  
  26. void newRandomMovie() {
  27.   int which = (int)random(totalMovies);
  28.   current = (current + 1) % 2;
  29.   mov[current] = new Movie(this, which + ".mp4");
  30.   mov[current].play();  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement