Hi Guys,
I’m trying to make a native App for work, where people can drag the sound file into data folder and run the AudioWaveform.app.
The problem is: When I launch for the first time the application it’s works, but when I remove the mp3 file from data folder and I add another one mp3 file the program is not running.
I don’t know how to fix this bug, because all work when I use Processing IDE but when I export the native application it’s work only the first time.
I attach the code below:
import ddf.minim.analysis.*;
import ddf.minim.*;
import com.hamoid.*;
import java.util.Date;
VideoExport videoExport;
Minim minim;
AudioPlayer player;
FFT fft;
String[] filenames;
String nomeFile;
float c = 1.2;
float dist;
int larghezza;
PFont font;
void setup() {
size(400, 400);
smooth();
font = loadFont("Avenir-Black-16.vlw");
textFont(font);
larghezza = round(width/60);
dist = larghezza*2;
String path = sketchPath("data");
filenames = listFileNames(path);
printArray(filenames);
for (int i = 0; i < filenames.length; i++) {
if (filenames[i].endsWith("mp3")) {
nomeFile = filenames[i];
minim = new Minim(this);
player = minim.loadFile(nomeFile);
}
}
//println("File audio: " + nomeFile);
//println("File " + ds + " trovato");
fft = new FFT(player.bufferSize(), player.sampleRate());
player.play();
}
void draw() {
background(0);
stroke(255);
fft.forward(player.mix);
for (int i = 0; i < fft.specSize(); i++) {
fill(255);
strokeWeight(0.5);
rect(i*dist, height/2, larghezza, fft.getBand(i) * -c);
rect(i*dist, height/2, larghezza, fft.getBand(i) * c);
}
for (int i = 0; i < filenames.length; i++) {
text(filenames[i], 15, 20*i+20);
}
}
// This function returns all the files in a directory as an array of Strings
String[] listFileNames(String dir) {
File file = new File(dir);
String names[] = file.list();
return names;
}