modify filechooser for videos?
in
Programming Questions
•
2 years ago
Hey all im quite new to processing and i was wondering if it was possible to modify this code so it imported and played video instead of images? Any feedback appreciated, thanks in advance.
import javax.swing.*; // this creates the design of the file browser based on java prefrences <3
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
// create a file chooser
final JFileChooser fc = new JFileChooser();
// in response to a button click:
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
// see if it's an image
// (better to write a function and check for all supported extensions)
if (file.getName().endsWith("jpg")) {
// load the image using the given file path
PImage img = loadImage(file.getPath());
if (img != null) {
// size the window and show the image
size(img.width,img.height);
image(img,0,0);
}
} else {
// just print the contents to the console
// note: loadStrings can take a Java File Object too
String lines[] = loadStrings(file);
for (int i = 0; i < lines.length; i++) {
println(lines[i]);
}
}
} else {
println("Open command cancelled by user.");
}
}
}
}
import javax.swing.*; // this creates the design of the file browser based on java prefrences <3
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
// create a file chooser
final JFileChooser fc = new JFileChooser();
// in response to a button click:
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
// see if it's an image
// (better to write a function and check for all supported extensions)
if (file.getName().endsWith("jpg")) {
// load the image using the given file path
PImage img = loadImage(file.getPath());
if (img != null) {
// size the window and show the image
size(img.width,img.height);
image(img,0,0);
}
} else {
// just print the contents to the console
// note: loadStrings can take a Java File Object too
String lines[] = loadStrings(file);
for (int i = 0; i < lines.length; i++) {
println(lines[i]);
}
}
} else {
println("Open command cancelled by user.");
}
}
}
}
1