help with mousePressed
in
Core Library Questions
•
2 years ago
I have had this re-occurring all day and i cant seem to stop it, when I browse for a file via mousePressed - find a mov movie and play it (the video plays on my laptop but on my desktop it appears white) the browse feature will then activate when the mouse is not pressed and i dont understand wh y(nullPointerException), please help. Thanks.
import processing.video.*;
Movie movie;
// horizontal and vertical grid count
// take care of the aspect ratio ... here 4:3
int tileCountX = 12;
int tileCountY = 16;
float tileWidth, tileHeight;
int imageCount = tileCountX*tileCountY;
int currentImage = 0;
int gridX = 0;
int gridY = 0;
//variables for rect
float x;
float y;
float w;
float h;
void setup()
{
size(1024, 1024);
smooth();
//variables for x,y,w,h are defined <3
x = width/2+112.5;
y = height/2-40;
w = 100;
h = 20;
}
void draw()
{
{
{
//large outer box
stroke(54,106,245,255);
strokeWeight(3.5);
fill(210);
rect((x-362.5),(y-147.5),500,375);
}
{
//top blue box
stroke(54,106,245,180);
strokeWeight(2.5);
fill(126,161,255);
rect((x-362.5),(y-147.5),500,32);
}
{
//file location view box
stroke(4,26,85,150);
strokeWeight(1.7);
fill(255);
rect((x-325),(y),306.25,h);
}
{
//noFill rect
stroke(0,11,41,35);
strokeWeight(1.6);
noFill();
rect((x-347.5),(y-15),470,50);
}
{
stroke(0,11,41,70);
strokeWeight(1.6);
line((x-347.5),y+182.5,x+120,y+182.5);
}
{
//the main browse rectangle
stroke(4,26,85,200);
strokeWeight(1.3);
fill(210);
rect(x,y,w,h);
}
{
//browse text
fill(0);
textSize(15);
text("Browse...",x+20,y,70,30);
}
{
// C: text
fill(0);
textSize(15);
text("C:",(x-323),y,70,30);
}
// welcome to WallVid text
fill(0,0,0,150);
textSize(20);
text("Welcome to WallVid, please select a file",(x-323),y-50);
}
//mouseClicks
if(mousePressed == true){
if(mouseX>x && mouseX <x+w && mouseY>y && mouseY <y+h){ // if the mouse is in box space + pressed
println("The mouse is pressed and over the button");
//do stuff
String loadPath = selectInput("select a video file ..."); // Opens file chooser
if (loadPath == null) {
// If a file was not selected
println("No file was selected...");
} else {
// If a file was selected, print path to file
println(loadPath);
}
// select path and load video
movie = new Movie(this, loadPath);
movie.play();
movie.loop();
movie.frameRate(125);
}
{
movie.read(); // read frame
image(movie,0,0); // display frame
// calculate the current time in movieclip
float moviePos = map(currentImage, 0,imageCount, 0,movie.duration());
}
}
}
public void init(){
// to make a frame not displayable, you can
// use frame.removeNotify()
frame.removeNotify();
frame.setUndecorated(true);
// addNotify, here i am not sure if you have
// to add notify again.
frame.addNotify();
super.init();
}
import processing.video.*;
Movie movie;
// horizontal and vertical grid count
// take care of the aspect ratio ... here 4:3
int tileCountX = 12;
int tileCountY = 16;
float tileWidth, tileHeight;
int imageCount = tileCountX*tileCountY;
int currentImage = 0;
int gridX = 0;
int gridY = 0;
//variables for rect
float x;
float y;
float w;
float h;
void setup()
{
size(1024, 1024);
smooth();
//variables for x,y,w,h are defined <3
x = width/2+112.5;
y = height/2-40;
w = 100;
h = 20;
}
void draw()
{
{
{
//large outer box
stroke(54,106,245,255);
strokeWeight(3.5);
fill(210);
rect((x-362.5),(y-147.5),500,375);
}
{
//top blue box
stroke(54,106,245,180);
strokeWeight(2.5);
fill(126,161,255);
rect((x-362.5),(y-147.5),500,32);
}
{
//file location view box
stroke(4,26,85,150);
strokeWeight(1.7);
fill(255);
rect((x-325),(y),306.25,h);
}
{
//noFill rect
stroke(0,11,41,35);
strokeWeight(1.6);
noFill();
rect((x-347.5),(y-15),470,50);
}
{
stroke(0,11,41,70);
strokeWeight(1.6);
line((x-347.5),y+182.5,x+120,y+182.5);
}
{
//the main browse rectangle
stroke(4,26,85,200);
strokeWeight(1.3);
fill(210);
rect(x,y,w,h);
}
{
//browse text
fill(0);
textSize(15);
text("Browse...",x+20,y,70,30);
}
{
// C: text
fill(0);
textSize(15);
text("C:",(x-323),y,70,30);
}
// welcome to WallVid text
fill(0,0,0,150);
textSize(20);
text("Welcome to WallVid, please select a file",(x-323),y-50);
}
//mouseClicks
if(mousePressed == true){
if(mouseX>x && mouseX <x+w && mouseY>y && mouseY <y+h){ // if the mouse is in box space + pressed
println("The mouse is pressed and over the button");
//do stuff
String loadPath = selectInput("select a video file ..."); // Opens file chooser
if (loadPath == null) {
// If a file was not selected
println("No file was selected...");
} else {
// If a file was selected, print path to file
println(loadPath);
}
// select path and load video
movie = new Movie(this, loadPath);
movie.play();
movie.loop();
movie.frameRate(125);
}
{
movie.read(); // read frame
image(movie,0,0); // display frame
// calculate the current time in movieclip
float moviePos = map(currentImage, 0,imageCount, 0,movie.duration());
}
}
}
public void init(){
// to make a frame not displayable, you can
// use frame.removeNotify()
frame.removeNotify();
frame.setUndecorated(true);
// addNotify, here i am not sure if you have
// to add notify again.
frame.addNotify();
super.init();
}
1