Randomised Video and Caption

edited April 2016 in Library Questions

Hallo everyone,

I am a beginner and I am trying to have a sketch which basically plays an amount of videos and then have underneath a scrolling text (stored in the data folder as .txt file). What I have right now is 10 videos playing one after the other, with each having a specific text. Is there any way where I can have a simpler code and having both randomised, in a continuous stream? Below is the sketch.

Very highly appreciate any help! Thanks.

Canny

(sorry i dont really know how to format the code to copy paste it in the right format)

Tagged:

Answers

  • edited March 2016
    import processing.video.*;
    Movie myMovie1, myMovie2, myMovie3, myMovie4, myMovie5, myMovie6, myMovie7, myMovie8, myMovie9, myMovie10, myMovie11;
    boolean playMovie1=true;
    boolean playMovie2=false;
    boolean playMovie3=false;
    boolean playMovie4=false;
    boolean playMovie5=false;
    boolean playMovie6=false;
    boolean playMovie7=false;
    boolean playMovie8=false;
    boolean playMovie9=false;
    boolean playMovie10=false;
    boolean playMovie11=false;
    float movieEndDuration = 1.029719;
    int x, y;
    String[] sub1;
    String[] sub2;
    String[] sub3;
    int mSub1ID = 0;
    int mSub2ID = 0;
    int mSub3ID = 0;
    int fps = 25;
    
    
    void setup() {
      size(800, 600);
      frameRate(fps);
      x = width;
      y = 200;
    
    
    
      textFont(createFont("BentonSansComp-Black", 60));
      textAlign(CENTER);
      fill(0);
      sub1 = loadStrings("sub1.txt");
      sub2 = loadStrings("sub2.txt");
      sub3 = loadStrings("sub3.txt");
    
      myMovie1 = new Movie(this, "vid2.mp4");
      myMovie2 = new Movie(this, "vid1.mp4");
      myMovie3 = new Movie(this, "vid3.mp4");
      myMovie4 = new Movie(this, "vid4.mp4");
      myMovie5 = new Movie(this, "vid5.mp4");
      myMovie6 = new Movie(this, "vid6.mp4");
      myMovie7 = new Movie(this, "vid7.mp4");
      myMovie8 = new Movie(this, "vid8.mp4");
      myMovie9 = new Movie(this, "vid9.mp4");
      myMovie10 = new Movie(this, "vid10.mp4");
      myMovie11 = new Movie(this, "vid11.mp4");
    }
    
    void draw() {
      background(0);
      fill(255);
      myMovie1.volume(0); 
      myMovie2.volume(0); 
      myMovie3.volume(0); 
      myMovie4.volume(0); 
      myMovie5.volume(0); 
      myMovie6.volume(0);
      myMovie7.volume(0); 
      myMovie8.volume(0); 
      myMovie9.volume(0); 
      myMovie10.volume(0); 
      myMovie11.volume(0); 
    
    
      if (playMovie1==true) {
        myMovie1.play();
    
        image(myMovie1, 0, 0, 800, 480);
    
    
        if (x < 0) {
          text((sub1[mSub1ID]), x + textWidth(sub1[mSub1ID]) + 50, 550);
        }
        text(sub1[mSub1ID], x, 550);
        x=x-7;
      }
    
    
      if ((myMovie1.time() + movieEndDuration) >= myMovie1.duration()) {
        {
          myMovie1.stop();
          playMovie1=false;
          playMovie2=true;
        }
      }
    
    
      if (playMovie2==true) {
    
        myMovie2.play();
        image(myMovie2, 0, 0);
        if (x < 0) {
          text((sub2[mSub2ID]), x + textWidth(sub2[mSub2ID]) + 50, 550);
        }
        text(sub2[mSub2ID], x, 550);
        x=x-7;
    
        if ((myMovie2.time() + movieEndDuration) >= myMovie2.duration()) {
          {
            myMovie2.stop();
            playMovie2=false;
            playMovie3=true;
          }
        }
      }
    
      if (playMovie3==true) {
    
        myMovie3.play();
        image(myMovie3, 0, 0 );
    
        if (x < 0) {
          text((sub3[mSub3ID]), x + textWidth(sub3[mSub3ID]) + 50, 550);
        }
        text(sub3[mSub3ID], x, 550);
        x=x-7;
    
        if ((myMovie3.time() + movieEndDuration) >= myMovie3.duration()) {
          {
            myMovie3.stop();
            playMovie3=false;
            playMovie4=true;
          }
        }
      }
    
      if (playMovie4==true) {
    
        myMovie4.play();
        image(myMovie4, 0, 0);
        if ((myMovie4.time() + movieEndDuration) >= myMovie4.duration()) {
          {
            myMovie4.stop();
            playMovie4=false;
            playMovie5=true;
          }
        }
      }
    
      if (playMovie5==true) {
    
        myMovie5.play();
        image(myMovie5, 0, 0);
        if ((myMovie5.time() + movieEndDuration) >= myMovie5.duration()) {
          {
            myMovie5.stop();
            playMovie5=false;
            playMovie6=true;
          }
        }
      }
    
      if (playMovie6==true) {
    
        myMovie6.play();
        image(myMovie6, 0, 0);
        if ((myMovie6.time() + movieEndDuration) >= myMovie6.duration()) {
          {
            myMovie6.stop();
            playMovie6=false;
            playMovie7=true;
          }
        }
      }
    
    
      if (playMovie7==true) {
    
        myMovie7.play();
        image(myMovie7, 0, 0);
        if ((myMovie7.time() + movieEndDuration) >= myMovie7.duration()) {
          {
            myMovie7.stop();
            playMovie7=false;
            playMovie8=true;
          }
        }
      }
    
    
      if (playMovie8==true) {
    
        myMovie8.play();
        image(myMovie8, 0, 0);
        if ((myMovie8.time() + movieEndDuration) >= myMovie8.duration()) {
          {
            myMovie8.stop();
            playMovie8=false;
            playMovie9=true;
          }
        }
      }
    
      if (playMovie9==true) {
    
        myMovie9.play();
        image(myMovie9, 0, 0);
        if ((myMovie9.time() + movieEndDuration) >= myMovie9.duration()) {
          {
            myMovie9.stop();
            playMovie9=false;
            playMovie10=true;
          }
        }
      }
    
      if (playMovie10==true) {
    
        myMovie9.play();
        image(myMovie10, 0, 0);
        if ((myMovie9.time() + movieEndDuration) >= myMovie10.duration()) {
          {
            myMovie10.stop();
            playMovie10=false;
            playMovie11=true;
          }
        }
      }
    
    
      if (playMovie11==true) {
        myMovie11.play();
        image(myMovie11, 0, 0);
    
        if ((myMovie11.time() + movieEndDuration) >= myMovie11.duration()) {
          {
            playMovie11=false;
            playMovie1=true;
          }
        }
      }
    }
    
    
    void movieEvent(Movie m) {
      m.read();
    }
    
  • please highlight code, press ctrl-o to format

  • Ah thank you! so now it's fomatted

  • ctrl-t in the processing editor to indent it nicely. makes the world of difference to readability.

  • Righto, done!

  • edited April 2016

    Hello all, the problem is solved with a help from a pro with a bit of tutorial for arrays.... below is the final code :) Thank you

  • edited April 2016 Answer ✓
        import processing.video.*;
        Movie myMovie1, myMovie2, myMovie3, myMovie4;
    
    
        int randomMovie;
        int randomSub;
        int amountOfMovies = 4; // amount of videos & text
        Movie[] myMovie = new Movie[amountOfMovies];
        float movieEndDuration = 1.029719;
        int x, y;
    
    
        String[][] sub;
        int fps = 25;
    
    
        void setup() {
          size(448, 336);
          frameRate(fps);
          x = width;
          y = 200;
    
    
    
          textFont(createFont("Courier-Bold", 60));
          textAlign(CENTER);
          fill(0);
    
          sub = new String[amountOfMovies][0];
    
          for (int i=0; i<myMovie.length; i++) {
            int num = i+1;
            myMovie[i] = new Movie(this, "vid"+num+".mp4");
            sub[i] = loadStrings("sub"+num+".txt");
          }
    
    
          randomMovie = int(random(0, amountOfMovies));
          randomSub = int(random(0, amountOfMovies));
        }
    
        void draw() {
    
          background(0);
          fill(255);
    
          myMovie[randomMovie].play();
          image(myMovie[randomMovie], 0, 0, 448, 336);
    
          if (x < 0) {
            text((sub[randomSub][0]), x + textWidth(sub[randomSub][0]) + 50, 300);
          }
          text(sub[randomSub][0], x, 300);
          x=x-9;
    
          if ((myMovie[randomMovie].time() + movieEndDuration) >= myMovie[randomMovie].duration()) {
    
            myMovie[randomMovie].stop();
            nextMovie(randomMovie, randomSub);
          }
        }
    
        void nextMovie(int lastMovie, int lastSub) {
          while (randomMovie == lastMovie) {
            randomMovie = int(random(0, amountOfMovies));
          }
          while (randomSub == lastSub) {
            randomSub = int(random(0, amountOfMovies));
          }
        }
    
        void movieEvent(Movie m) {
          m.read();
        }
    
Sign In or Register to comment.