Category Archives: Resource

{resource} Minim example

/* playing sound file according to mouse X position */

import ddf.minim.*;

Minim minim;
AudioPlayer name;
int index = 1;

int x;

boolean firstStart = false;

void setup() {
size(300, 200, P3D);
//LOADSAMPLE

minim = new Minim(this);
name = minim.loadFile(“0.wav”, 2048);
}

void draw() {

background(0);

if(firstStart == false){ // THIS WILL RUN ONLY ONE TIME TO START
x = int(random(0,4));
name = minim.loadFile(x + “.wav”, 2048);//PLAY AN AUDIO FILE to start
name.play();
firstStart = true;
}else{ // THIS PART WILL BE REPEAT
//CHECK IF ANY AUDIO FILE IS BEING PLAYED
if(name.isPlaying() == false){
delay(500);
x = int(mouseX /100);
println(x);
// x = int(random(0,4));// CHOOSE RANDOM NUMBER
name = minim.loadFile(x + “.wav”, 2048); //LOAD ‘THE’ RANDOM AUDIO FILE
name.play();// PLAY IT

//PRINT THE PICKED RANDOM NUMBER
}

}

void stop() {
name.close();
minim.stop();
super.stop();
}

DOWNLOAD CODE