We are about to switch to a new forum software. Until then we have removed the registration on this forum.
need a bit of help with this code. I'm trying to adapt a sketch I made originally for my laptop with the video library. It's pretty simple, I'm reading the values 1 and 0 from the serial port and switching between two synched clips each time there's a change. I'm not having such successful results trying to recreate this with GLVideo however, which I've never used before. hopefully I can fairly easily achieve what I want?
thanks for any help you might have
import processing.serial.*;
Serial myPort;
int val=0;
import gohai.glvideo.*;
GLMovie[]video = new GLMovie [2];
int i =0;
void setup() {
fullScreen(P2D);
String portName = Serial.list()[0];
myPort= new Serial (this, portName,115200);
video [0] = new GLMovie(this, "low.mp4");
video [1] = new GLMovie (this, "high.mp4");
video [i].loop();
}
void draw() {
image(video[i],0,0,width,height);
if (video[i].available()) {
video[i].read();
}
}
void serialEvent(Serial p) {
if (myPort.available()>0) {
val=myPort.read();
println(val);
}
if (val==0) {
i=1;
}
else {
i=0;
}
}
Answers
Not sure about GLvideo... it is possible you got this from an old post. Check these next posts and give it a try. If you get stuck, provide a minimum example showing your problem and provide relevant details:
https://forum.processing.org/two/discussion/23419/video-play-random-video-sequence#latest
https://forum.processing.org/two/discussion/22640/can-anyone-help-me-find-what-s-wrong-with-my-code-for-a-video-player-based-off-sensor-reading#latest
Kf
@everyday90
On a cursory glance, this looks good to me. You'll get better performance if you always erase the background inside draw, since this signals to the renderer that it doesn't need to keep around the previous frame content any longer, so:
Added the background line but so far I'm only getting a succesful response from one of the two videos (apparently whichever one corresponds to the correct value of i at at the beginning of the sketch) while the counterpart just returns a black screen. Have tried it with several different clips and this is the case each time.
Notice line 14. You are calling loop only for i=0. Try calling loop() for both videos.
A quick simple check to see if your movies are working would be to play one movie at the time. However, I don't think the problems are your movies.
Also, I don't think you need to check if myport.available() inside the serialEvent() function as this function is called every time data arrives at the serial port.
Kf