0

I want to play videos in two windows by using just one single sketch in Processing. And I also want to use serial communication.. serial communication does well but a video doesn't work. I guess the program can't find where video is.

I've searched more than one window of a single sketch in Processing. I referred to this. How to create more than one window of a single sketch in Processing?

Here is the codes that I wrote.

I hope you help me please


Code

import processing.video.*;
import processing.serial.*;

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

Movie mov;

void setup() {
  size(100, 100);

  String[] args = {"TwoFrameTest"};


 SecondApplet sa = new SecondApplet();
  ThirdApplet na = new ThirdApplet();
  PApplet.runSketch(args, sa);
  PApplet.runSketch(args, na);

  String portName = Serial.list()[1];
  myPort = new Serial(this, portName, 9600);

  sa.mov = new Movie(this, "transit.mov");
  sa.mov.loop();

}




void draw() {
  background(0);
  ellipse(50, 50, 10, 10);

  if (myPort.available() > 0) {
    if ( (val = myPort.readStringUntil(ENTER)) != null )  val = trim(val);
    else return;
    if (val != null) {
      println(val);
    }
    }

}     

public class SecondApplet extends PApplet {
public Movie mov;

  public void settings() {
    size(500, 500);
  }


  public void draw() {

    fill(0);
    ellipse(100, 50, 10, 10);

  if ("3Low".equals(val)) {
    fill(255,random(255),200);
      ellipse(60,20,100,100);
    }

    sa.image(sa.mov,0,0);

  }
}



public class ThirdApplet extends PApplet {


  public void settings() {
    size(500, 500);
  }

  public void draw() {

    fill(0);
    ellipse(100, 50, 10, 10);

  if ("3Low".equals(val)) {
    fill(255,random(255),200);
      ellipse(60,20,100,100);
    }


  }
}
Community
  • 1
  • 1

1 Answers1

0

I guess the program can't find where video is.

Please be more specific. What exact error message do you see? What do you expect to happen? What happens instead?

I want to play videos in two windows by using just one single sketch in Processing.

The code you posted uses three different sketches, and you're doing weird things with the scope of each. Just write each sketch as if they were completely separate, and then add the linking code last.

I don't see why you wouldn't be able to use two different sketches to play two different movies. It might look something like this:

Movie movieOne;

void setup() {
  size(100, 100);

  movieOne = new Movie(this, "MovieOne.mov");
  movieOne.loop();

  String[] args = {"SecondSketch"};
  SecondSketch sa = new SecondSketch();
  PApplet.runSketch(args, sa);
}

void draw() {
  image(movieOne, 0, 0);
}     

public class SecondSketch extends PApplet {
  Movie movieTwo;

  public void settings() {
    size(500, 500);
    movieTwo = new Movie(this, "MovieTwo.mov");
    movieTwo.loop();
  }

  public void draw() {
    image(movieTwo, 0, 0);
  }
}

Please note that this is just example code, and I haven't even tried to compile it. You'll probably have to change a few things to get it working, but this should give you a general idea of the approach to take.

A simpler option might be to create two buffers using the createGraphics() function. Draw a movie to each buffer, and then draw the buffers to the screen.

Movie movieOne;
Movie movieTwo;

PGraphics bufferOne;
PGraphics bufferTwo;

void setup() {
  size(1000, 500);

  bufferOne = createGraphics(500, 500);
  bufferTwo = createGraphics(500, 500);

  movieOne = new Movie(this, "MovieOne.mov");
  movieOne.loop();

  movieTwo = new Movie(this, "MovieTwo.mov");
  movieTwo.loop();
}

void draw() {
  bufferOne.beginDraw();
  bufferOne.image(movieOne, 0, 0);
  bufferOne.endDraw();

  bufferTwo.beginDraw();
  bufferTwo.image(movieTwo, 0, 0);
  bufferTwo.endDraw();

  image(bufferOne, 0, 0);
  image(bufferTwo, 500, 0);
}   

Again, this is just example code that you might have to modify to get working perfectly.

More info can be found in the refrence.

If you still can't get it working, please post an updated MCVE in a new question, and we'll go from there.

Community
  • 1
  • 1
Kevin Workman
  • 41,537
  • 9
  • 68
  • 107