make minim sound repeat?please help:)
in
Core Library Questions
•
11 months ago
hey guys unfamilliar with minim and just wondering how/what where to put the sound clip to make it play from the beginning every time the mouse if clicked..?so with the follwing code have managed to make it play when the mouse is clicked however it only works once and doesnt repeat unless you re-run the application.thanks for the help:)
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
Minim minim;
AudioPlayer sou;
int tri_count = 100;
float[]xp2=new float[tri_count];
float[]yp2=new float[tri_count];
float[]speed2=new float [tri_count];
float[] xp = new float[tri_count];
float[] yp = new float[tri_count];
float[] speed = new float[tri_count];
int i = 0;
int col = 255;
float siz = 30;
int col1=161;
int col2=0;
int col3=192;
int alpha=90;
void setup() {
size(500, 500);
int i = 0;
while ( i < tri_count) {
xp2[i]=random (0, width);
yp2[i]=random (0, width);
speed2[i]=random (0.1, 2);
xp[i] = random(0, width);
yp[i] = random(0, height);
speed[i] = random(0.02, 5);
minim=new Minim (this);
sou=minim.loadFile ("xylophone_open.mp3");
i = i + 1;
}
}
void draw() {
//background(255);
fill( 228, 228, 228, 10);
rect( 0, 0, width, height);
strokeWeight(0.5);
update_main_layer();
gfx2();
gfx();
attract();
update_background();
}
void gfx() {
strokeWeight (1.5);
stroke (255, 255, 255,40);
fill (17, 192, 16, 20);
/* stops code and symbol below starts it
*/
int i = 0;
int angle = 0;
while ( i < tri_count) {
pushMatrix();
translate(xp[i], yp[i]);
rotate(angle);
triangle(xp[i]-15, yp[i]+ 30, xp[i], yp[i], xp[i]+15, yp[i]+15);
popMatrix();
i = i + 1;
angle = angle+1;
}
}
void update_background() {
int i = 0;
while ( i < tri_count) {
yp[i] = yp[i] + speed[i];
if (yp[i] >width) {
yp[i] = -40;
}
i = i + 1;
}
}
void gfx2() {
fill (col1, col2, col3, 25);
stroke(col);
int i=0;
int angle=0;
angle = angle + 10;
while ( i< tri_count) {
pushMatrix();
translate(xp2[i],yp2[i]);
rotate(angle);
triangle(xp2[i]-siz, yp2[i]+siz, xp2[i], yp2[i], xp2[i]+siz, yp2[i]+siz);
popMatrix();
i = i + 1;
angle = angle+1;
}
}
void update_main_layer() {
int i = 0;
while ( i < tri_count) {
if(dist(xp2[i],yp2[i],mouseX,mouseY) < 10){
xp2[i]=mouseX;
yp2[i]=mouseY;
sou.play();
}
else{
yp2[i] = yp2[i] + speed2[i];
}
if (yp2[i] >width) {
yp2[i] = -40;
}
i = i + 1;
}
}
void attract() {
for (i = 0; i < tri_count; i++); {
if (mousePressed == true) {
sou.play();
siz = siz + 10;
if (siz >= 300) {
col1 = 161;
col2 = 0;
col3 = 192;
} else {
col1 = 34;
col2 = 144;
col3 = 9;
}
col = 100;
} else {
siz = siz / 1.3;
col = 255;
}
if (mousePressed == false) {
sou.pause();
}
}
//class attraction {
// if (mouseX=[i]-30, mouseY=[i]+30, mouseX=[i], mouseY[i], mouseX[i]+30, mouseY[i]+30)
// triangle (xp2[i]-30, yp2[i]+30, xp2[i], yp2[i], xp2[i]+30, yp2[i]+30);
}
1