Minim Mp3 play at certain point in time based on millis()

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();
  }
}`
Tagged:

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.

  • edited April 2015

    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(); } }`

Sign In or Register to comment.