We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I am working on a project that involves a lot of videos files and interaction. I have a problem when combining the sketches I did separately into one standalone program and make it as smooth as it was when played separately. That means each of the sketches was played fine until they are now combined. I am curious that the problem comes from the order of code lines and how to call the video. So I made it loads the video files first and plays them when pressing a button on a selected name ( change String). The frame rate I put is frameRate(60) at the end of setup() due to the gifAnimation library I use to play with gif images. I've tried 30 it is slightly lagging but I think it is actually fine; however, the videos still have a spasm.
Also, in this program, there is a lot of information that has been load first and receiving in real-time. I am working with API from twitter and Tumblr, and detecting Arduino sensors. (The videos I'm having a problem with is not live tho.) Will this can be the one causes the program of video lagging?
Idk which part of the code should I put in here so I attach the setup() and draw() here:
void settings() {
PJOGL.profile=1;
if (install == true) {
fullScreen(SPAN);
} else {
size((projectorWidth*3)/scalar, projectorHeight/scalar, P3D);
}
}
void setup() {
canvas = createGraphics((projectorWidth*3)/scalar, projectorHeight/scalar, P3D);
server = new SyphonServer(this, "Processing Syphon");
//--------///
if (!debugging) {
myPort = new Serial(this, Serial.list()[7], 9600); // Open whatever port is the one you're using for arduino.
myPort.clear();
myString = myPort.readStringUntil(lf);
myString = null;
}
//Youtubue
loadMovies(); //not live from website. it just grabs from internal folder.
// Instagram
runGetRecentMediaForUserChoreo();
//Twitter
twitterFont = createFont("Helvetica Neu Bold", 30);
runTweetsChoreo(); // Run the Tweets Choreo function
getTweetFromJSON(); // Parse the JSON response
//tumblr
runRetrievePostsWithTagChoreo();
searchJSON();
frameRate(60);
}
void draw() {
//Loading Screen Code//
switch(startPhase) {
case 0:
//println("startPhase: "+startPhase);
thread("FilesLoading"); //Use thread() to load files or do other tasks that take time. When
// the task is finished, set a variable that indicates the task is complete, and check that from inside your draw() method.
startPhase++;
return;
case 1: //call function to load files.
//println("startPhase: "+startPhase);
Loadingtxt();
return;
case 2: //currently loading files.
canvas.beginDraw();
if (!debugging) {
while (myPort.available() > 0) {
myString = myPort.readStringUntil(lf);
if (myString != null) {
myString = trim(myString);
value = int(myString);
println(value);
if (value <275) {
sensorSwitch=true;
myMovie[num].stop();
background(0);
}
if (sensorSwitch) {
if (value>=275) {
println("Force sensor is detacted");
newRandom=true;
randomMovie();
sensorSwitch=false;
}
}
}
}
if (value<275) {
canvas.background(0);
println("black background is on top.");
}
}
canvas.textAlign(CENTER, CENTER);
canvas.textSize(14);
canvas.fill(255);
canvas.text("Movie is not playing.", width/2, height/2);
canvas.background(0);
displayYoutube();
displayText();
displayPic();
displayTumblr();
displayGif();
/*if (!debugging) {
if (value<275) {
canvas.background(0);
println("black background is on top.");
}
}*/
canvas.endDraw();
image(canvas, 0, 0);
server.sendImage(canvas);
randomMovie();
return;
}
}
Thanks.
Answers
https://forum.processing.org/two/discussion/15473/readme-how-to-format-code-and-text#latest
@TfGuy44 I think you came too early when the 'C' line didn't work. I did insert the code tag but it did not work. However, I fixed it now. Anyway, Thanks tho.
I am not fond of you using line 50 there. You have a while inside the draw() function, which is a while function by itself. You should consider using the proper callbacks: serialEvent() and movieEvent(). There are plethora of examples in the forum.
Kf
Hi @kfrajer,
Thank you for your suggestion. I did try several ways based on yours. The serialEvent() seemed better like you said. Actually, you replied my other post about a serial port problem I ran into. Lol. However, the movieEvent() didn't work. I did found that available() for movie will run faster than the actual movieEvent() . Someone posted it on the Internet and I think it's true.
So now, I'm good with the movie there is no lag anymore. Hooray!... but the serial port linked from Arduino still.... ;(