play videos and mousepressed

edited March 2018 in Arduino

Hi, i am recently doing some work using processing and arduino. i am new.. so it might be basic question. there are totally 7 videos. and two separate arrays(or playlist)? list1>videos 1, 2, 3, 4 list2> videos 5,6,7

so when it starts, list1 will be played, (1-4) and if you press the mouse, current video will stop and playlist 2 videos randomly (5~7). and after the video ends, it returns to play list1.

this code is working to playing list 1 and if i press the mouse, the movie stops for a sec and play again. not going to play list 2...

TT...

  import processing.serial.*;
  import cc.arduino.*;
  import processing.video.*;


  Serial myPort;  // Create object from Serial class
  String val;     // Data received from the serial port
  Arduino arduino;

  int buttonPin = 7;

  Movie myMovie1, myMovie2, myMovie3, myMovie4, myMovie5;
  boolean playMovie1=true;
  boolean playMovie2=false;
  boolean playMovie3=false;
  boolean playMovie4=false;
  boolean playMovie5=false;
  float movieEndDuration = 1.029719;

  int fps = 25;
  String[] moviesNames = { 
    "4.mp4", "5.mp4", "6.mp4" };
  int index = int(random(moviesNames.length));
  Movie[] movies;

  void setup() {
    myPort = new Serial(this,"/dev/cu.usbmodem1451", 9600);
    String portName = Serial.list()[0]; //change the 0 to a 1 or 2 etc. to match your port
    arduino = new Arduino(this, Arduino.list()[0], 9600);
    arduino.pinMode(buttonPin, Arduino.INPUT);
    size(1280, 360);
    frameRate(fps);
    movies = new Movie[moviesNames.length];
    for (int i = 0; i < moviesNames.length; i++) {
      movies[i] = new Movie(this, moviesNames[i]);
    }
    myMovie1 = new Movie(this, "t0.mp4");
    myMovie2 = new Movie(this, "t1.mp4");
    myMovie3 = new Movie(this, "t2.mp4");
    myMovie4 = new Movie(this, "t3.mp4");
    myMovie5 = new Movie(this, "t4.mp4");
  }

  void draw() {
    background(0);
    myMovie1.volume(10); 
    myMovie2.volume(10); 
    myMovie3.volume(10); 
    myMovie4.volume(10); 
    myMovie5.volume(10); 
    image(movies[index], 0, 0, width, height);


  if (playMovie1==true) {
    myMovie1.play();
    image(myMovie1, 0, 0, width, height);


  }


  if ((myMovie1.time() + movieEndDuration) >= myMovie1.duration()) {
    {
      myMovie1.stop();
      playMovie1=false;
      playMovie2=true;
    }
  }


  if (playMovie2==true) {

    myMovie2.play();
    image(myMovie2, 0, 0, width, height);

    if ((myMovie2.time() + movieEndDuration) >= myMovie2.duration()) {
      {
        myMovie2.stop();
        playMovie2=false;
        playMovie3=true;
      }
    }
  }

  if (playMovie3==true) {

    myMovie3.play();
    image(myMovie3, 0, 0, width, height );

    if ((myMovie3.time() + movieEndDuration) >= myMovie3.duration()) {
      {
        myMovie3.stop();
        playMovie3=false;
        playMovie4=true;
      }
    }
  }

  if (playMovie4==true) {

    myMovie4.play();
    image(myMovie4, 0, 0, width, height);
    if ((myMovie4.time() + movieEndDuration) >= myMovie4.duration()) {
      {
        playMovie4=false;
        playMovie5=true;
      }
    }
  }
  }
  void movieEvent(Movie m) {
    m.read();
  }



  // Stops the movie playback when the mouse pressed
  void mousePressed() {
     myMovie1.stop();
    myMovie2.stop();
     myMovie3.stop();
    myMovie5.stop();
     movies[index].play(); 
     // assign newly picked random value to index:
  movies[index].loop(); // and start playing it.
  // Stops the movie playback when the mouse pressed
   int rnd; // keep picking a new index till got a diff. 1:
  while ( (rnd = (int) random(movies.length)) == index );

  // assign newly picked random value to index:
  movies[index].loop(); // and start playing it.
  } 
Tagged:

Answers

Sign In or Register to comment.