import ddf.minim.*; Minim minim; AudioPlayer player; String audioListFile = "data/rec/fileList.txt"; String[] listOfFiles; String fileToPlay; int timeToPlay; int timeMonitor = 0; int curTrackLength = 0; Boolean endSounds = false; void setup(){ size(512,200); minim = new Minim(this); listOfFiles = loadStrings(audioListFile); setupSound(); } void draw(){ background(0); int now = int(millis()/1000); if (!endSounds){ if (now > (timeMonitor + timeToPlay)){ initSound(); timeMonitor = timeMonitor + timeToPlay; setupSound(); } } else { player.close(); } } void stop(){ player.close(); minim.stop(); super.stop(); } void setupSound(){ int soundCount = listOfFiles.length; if (soundCount > 0){ int rIndex = int(random(listOfFiles.length)); fileToPlay = listOfFiles[rIndex]; String[] tempA = subset(listOfFiles, 0, rIndex); String[] tempB = subset(listOfFiles, rIndex+1); tempA = splice(tempA, tempB, rIndex); listOfFiles = tempA; timeToPlay = int(random(10)); } else { endSounds = true; } } void initSound(){ player = minim.loadFile(fileToPlay, 2048); AudioMetaData meta = player.getMetaData(); curTrackLength = meta.length(); timeToPlay = timeToPlay + int((curTrackLength/1000)) + 1; player.play(); }