CharlieSilverman
YaBB Newbies
Offline
Posts: 2
Minim Stop Question
Mar 29th , 2010, 12:46pm
I'm creating a piano type player and want to load different audio files at different times, then have the others stop. I have separate players player at different mouse coordinates, but they all continue to play. How can I achieve this?! Below is my code for reference: //charlie silverman //march 2010 float bright0 = 255; float bright1 = 255; float bright2 = 255; float bright3 = 255; float bright4 = 255; float bright5 = 255; float bright6 = 255; float bright7 = 255; float bright8 = 255; float bright9 = 255; float bright10 = 255; float bright11 = 255; float bright12 = 255; float bright13 = 255; float bright14 = 255; float bright15 = 255; float bright16 = 255; import ddf.minim.*; AudioPlayer player1; AudioPlayer player2; Minim minim; void setup() { size(500,200); strokeWeight(2.0); minim = new Minim(this); player1=minim.loadFile("03 Barfly.mp3", 2048); player2=minim.loadFile("01 Homesick.mp3", 2048); } void draw() { // Draw the background background(255); // Depending on the mouse location, a // different rectangle is set to brightness 255 if (mouseX>0 && mouseX < 50 && mouseY > 100) { bright0 = 0; player2.play(); } else if (mouseX>50 && mouseX < 100 && mouseY > 100) { bright1 = 0; player1.play(); } else if (mouseX>100 && mouseX < 150 && mouseY > 100) { bright2 = 0; } else if (mouseX>150 &&mouseX < 200 && mouseY > 100) { bright3 = 0; } else if (mouseX>200 && mouseX < 250 && mouseY > 100) { bright4 = 0; } else if (mouseX>250 && mouseX < 300 && mouseY > 100) { bright5 = 0; } else if (mouseX>300 && mouseX < 350 && mouseY > 100) { bright6 = 0; } else if (mouseX>350 && mouseX < 400 && mouseY > 100) { bright7 = 0; } else if (mouseX>400 && mouseX < 450 && mouseY > 100) { bright8 = 0; } else if (mouseX>450 && mouseX < 500 && mouseY > 100) { bright9 = 0; } else if (mouseX>40 && mouseX < 60 && mouseY < 100) { bright10 = 0; } else if (mouseX>90 && mouseX < 110 && mouseY < 100) { bright11 = 0; } else if (mouseX>190 &&mouseX < 210 && mouseY < 100) { bright12 = 0; } else if (mouseX>240 && mouseX < 260 && mouseY < 100) { bright13 = 0; } else if (mouseX>290 && mouseX < 310 && mouseY < 100) { bright14 = 0; } else if (mouseX>390 && mouseX < 410 && mouseY < 100) { bright15 = 0; } else if (mouseX>440 && mouseX < 460 && mouseY < 100) { bright16 = 0; } // All rectangles always fade bright0 = bright0 + 2; bright1 = bright1 + 2; bright2 = bright2 + 2; bright3 = bright3 + 2; bright4 = bright4 + 2; bright5 = bright5 + 2; bright6 = bright6 + 2; bright7 = bright7 + 2; bright8 = bright8 + 2; bright9 = bright9 + 2; bright10 = bright10 + 2; bright11 = bright11 + 2; bright12 = bright12 + 2; bright13 = bright13 + 2; bright14 = bright14 + 2; bright15 = bright15 + 2; bright16 = bright16 +2; // Fill color and draw each rectangle smooth(); fill(255); stroke(bright0); rect(0,0,50,200); stroke(bright1); rect(50,0,100,200); stroke(bright2); rect(100,0,150,200); stroke(bright3); rect(150,0,200,200); stroke(bright4); rect(200,0,250,200); stroke(bright5); rect(250,0,300,200); stroke(bright6); rect(300,0,350,200); stroke(bright7); rect(350,0,400,200); stroke(bright8); rect(400,0,450,200); stroke(bright9); rect(450,0,500,200); noStroke(); fill(bright10); rect(40,0,20,100); fill(bright11); rect(90,0,20,100); fill(bright12); rect(190,0,20,100); fill(bright13); rect(240,0,20,100); fill(bright14); rect(290,0,20,100); fill(bright15); rect(390,0,20,100); fill(bright16); rect(440,0,20,100); } void stop() { // always close Minim audio classes when you are done with them player1.close(); player2.close(); minim.stop(); super.stop(); }