Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.nio.file.Path;
- import processing.sound.*;
- SoundFile file;
- boolean loading = true;
- boolean loadingphase2 = false;
- boolean select;
- boolean processing;
- boolean playing;
- String from;
- String newPath;
- boolean folderSelected = false;
- boolean fileSelected = false;
- void setup() {
- size(600,300);
- }
- void draw() {
- if(loading) {
- loading();
- }
- if(select) {
- select();
- }
- if(processing) {
- processing();
- }
- if(playing) {
- playing();
- }
- }
- void loading() {
- background(0);
- textSize(20);
- textAlign(CENTER);
- fill(255);
- text("Hello, please choose an mp3 file to play.", width/2, height/2-100);
- fill(25,255,255);
- rect(width/2-100, height/2-50, 200, 50);
- textAlign(CENTER);
- textSize(30);
- fill(0);
- text("LOADING...", width/2, height/2-15);
- while(loadingphase2) {
- delay(3000);
- select = true;
- loading = false;
- loadingphase2 = false;
- }
- loadingphase2 = true;
- }
- void select() {
- background(0);
- textSize(20);
- textAlign(CENTER);
- fill(255);
- text("Hello, please choose an mp3 file to play.", width/2, height/2-100);
- fill(25,255,255);
- rect(width/2-100, height/2-50, 200, 50);
- textAlign(CENTER);
- textSize(30);
- fill(0);
- text("UPLOAD", width/2, height/2-15);
- }
- void processing() {
- background(0);
- textSize(20);
- textAlign(CENTER);
- fill(255);
- text("Nicely done! Now, please select the 'data' folder. /n It's in the folder with this code-app.", width/2, height/2-100);
- fill(25,255,255);
- rect(width/2-100, height/2-50, 200, 50);
- textAlign(CENTER);
- textSize(30);
- fill(0);
- text("SELECT", width/2, height/2-15);
- }
- void playing() {
- if(fileSelected) {
- background(0);
- textSize(30);
- textAlign(CENTER);
- text("Alright, enjoy the music.", width/2, height/2);
- file = new SoundFile(this, "music.mp3");
- file.play();
- fileSelected = false;
- playing = false;
- }
- }
- void fileSelected(File selection) {
- if (selection == null) {
- println("Window was closed or the user hit cancel.");
- } else {
- from = selection.getPath();
- Path to = selection.get(sketchPath()+"/data/"+"music.mp3");
- selection.copy(from, to);
- fileSelected = true;
- playing = true;
- select = false;
- }
- }
- /*void folderSelected(File selection) {
- if (selection == null) {
- println("Window was closed or the user hit cancel.");
- } else {
- Path to = selection.getAbsolutePath();
- Files.copy(from, to.resolve(source.getFileName()));
- folderSelected = true;
- playing = true;
- processing = false;
- }
- }*/
- void mouseReleased() {
- if(mouseX <= width/2+100 && mouseX >= width/2-100 && mouseY <= height/2+50 && mouseY >= height/2-50 && select) {
- selectInput("Select an mp3 file to play.", "fileSelected");
- }
- /* if(mouseX <= width/2+100 && mouseX >= width/2-100 && mouseY <= height/2+50 && mouseY >= height/2-50 && processing) {
- selectFolder("Select a folder to process:", "folderSelected");
- }*/
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement