We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am new to Processing.
I am working on a code that so far is able to open an gmail account using POP3 and projects a video according to the subject text.
Using only the 'subject' I have been able to modify the PATH value of the next expression,
movies = new Movie (this, PATH0)
So when running the program, it opens the gmail account, takes only the subject content and projects a video according to the PATH value.
if (subject.equals("1")){
movies = new Movie (this, PATH01);
} else if (subject.equals("2")) {
movies = new Movie (this, PATH02);
} //and so on
What I want to do is to call for the function that checks the email checkMail() right after every video is finished. And in consequence of checking again the email account, the program must project a new video, if the subject line of the email is new or different.
The loop I created has worked badly.
//project movie and loop
void draw() {
background(255);
if (movies.available()) {
movies.read();
}
image(movies, 0, 0);
float md = movies.duration();
float mt = movies.time();
int a = int(md);
int b = int(mt);
if (a == b) {
movies.stop();
checkMail();
movies.play();
}
}
It seams to be quite unstable, it opens the email and changes the video about 15 times, no more than that! I have run it too many times... It stops checking the email after the video is finished. If you noticed the checkMail() is part of the setup(), so I am aware that this could be problematic, to call again a function that is in the setup(), but it seems to work, at least a few times. How can I make it run again?
I hope I made myself clear of what I want to do.
Your help will be very very much appreciated, I loosing my mind here...
~~~~~~ HERE IS THE ENTIRE CODE, including the authorizing and opening the gmail account.
// Under the main tab
import processing.video.*;
String PATH00 = "/Users/Documents/Videos/00.mp4";
String PATH01 = "/Users/Documents/Videos/01.mp4";
String PATH02 = "/Users/Documents/Videos/02.mp4";
String PATH03 = "/Users/Documents/Videos/03.mp4";
String PATH04 = "/Users/Documents/Videos/04.mp4";
Movie movies;
void setup() {
// Function to check mail
checkMail();
//create canvas
size(1280,720,P2D);
frameRate(24);
movies.play();
movies.speed(1);
movies.volume(1);
}
//project movie and loop
void draw() {
background(255);
if (movies.available()) {
movies.read();
}
image(movies, 0, 0);
float md = movies.duration();
float mt = movies.time();
int a = int(md);
int b = int(mt);
if (a == b) {
movies.stop();
checkMail();
movies.play();
}
}
// gmail authorizing tab
//Simple Authenticator
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;
public class Auth extends Authenticator {
public Auth() {
super();
}
public PasswordAuthentication getPasswordAuthentication() {
String username, password;
username = "YOUREMAIL@gmail.com";
password = "YOURPASSWORD";
System.out.println("Authenticating... ");
return new PasswordAuthentication(username, password);
}
}
// under the tab MAIL
void checkMail() {
try {
Properties props = System.getProperties();
props.put("mail.pop3.host", "pop.gmail.com");
// These are security settings required for gmail
props.put("mail.pop3.port", "995");
props.put("mail.pop3.starttls.enable", "true");
props.setProperty("mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.pop3.socketFactory.class","javax.net.ssl.SSLSocketFactory");
// Create authentication object
Auth auth = new Auth();
// Make a session
Session session = Session.getDefaultInstance(props, auth);
Store store = session.getStore("pop3");
store.connect();
// Get inbox
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
System.out.println(folder.getMessageCount() + " total messages.");
// Get array of messages and display them
Message message[] = folder.getMessages();
for (int i=0; i < message.length; i++){
System.out.println("---------------------");
System.out.println("Message # " + (i+1));
System.out.println("Message: " + message[i].getSubject());
String content = (message[i].getSubject());
if (content.equals("0")){
movies = new Movie (this, PATH00);
} else if (content.equals("1")){
movies = new Movie (this, PATH01);
} else if (content.equals("2")){
movies = new Movie (this, PATH02);
} else if (content.equals("3")){
movies = new Movie (this, PATH03);
} else if (content.equals("4")){
movies = new Movie (this, PATH04);
}
} catch (NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
Comments
See How to format code and text for formatting code (keyboard shortcut is currently Ctrl+O).
First thing I would try is to see if a is never equal to b. You could just add println(a, b); at the end of the draw loop to see what the values are.
@whitepapel:: i have made something like you want. ---Sometimes there are problems to know wether duration==time, dont know why, depends of the video itself; in order to be sure i have also used another library than processing, which has a "isPlaying()" method, codeanticode.gsvideo lib. Results are much sure. --- my code is not the same as yours: i create a method for checkMail, out of set up; ----i use imap and not pop3 ----i have my video paths in a String[] ----i have my keywords in a String[] and everything is ok....till now....