We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey I am trying to use minim to play a sound when a certain time (millis) is reached. Here is my code can anyone tell me what i am doing wrong?
`int time = millis() / 1000;
import ddf.minim.*;
Minim minim;
AudioPlayer player;
void setup(){
size(600, 450);
}
void draw() {
println(millis());
if(millis() == 60000){
minim = new Minim(this);
player = minim.loadFile("bang.mp3");
player.play();
}
if(millis() == 300000){
minim = new Minim(this);
player = minim.loadFile("bang.mp3");
player.play();
}
if(millis() == 360000){
minim = new Minim(this);
player = minim.loadFile("bang.mp3");
player.play();
delay (850);
minim = new Minim(this);
player = minim.loadFile("bang.mp3");
player.play();
}
}`
Answers
One thing that stands out to me is that you're checking for an exact millisecond value. Since the draw() function only fires 60 times per second, you won't get exact values like that.
Instead, you need to check whether you've played each sound, and then play each sound when millis() becomes greater than some value.
thank you so much kevin. here is the code for anyone who wants it. `import ddf.minim.*;
Minim minim; AudioPlayer player; void setup(){ size(600, 450); } void draw() { println(millis() / 1000); if((millis() > 60000) && (millis() < 60020)){ minim = new Minim(this); player = minim.loadFile("bang.mp3"); player.play(); } if((millis() > 300000) && (millis() < 300020)){ minim = new Minim(this); player = minim.loadFile("bang.mp3"); player.play(); } if((millis() > 360000) && (millis() < 360020)){ minim = new Minim(this); player = minim.loadFile("bang.mp3"); player.play(); } if((millis() > 360840) && (millis() < 360860)){ minim = new Minim(this); player = minim.loadFile("bang.mp3"); player.play(); } if((millis() > 380000) && (millis() < 387000)){ minim = new Minim(this); player = minim.loadFile("clapping.mp3"); player.play(); } }`