Question

I am trying to have two different delays at the beginning and the same delay between each sound on repeat for a project, there is no stop time in this. I tried using delay but it seems to just add the two delays instead of separating them, I was told to use millis(); function but am not sure how to implement this? Any help would be amazing!

import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;



import ddf.minim.*;

Minim minim;
AudioPlayer player;
AudioPlayer player2;

void setup()
{
  size(512, 200, P3D);

   minim = new Minim(this);

  player = minim.loadFile("clapping.mp3");
  player2 = minim.loadFile("bell.mp3");

}

void draw()
{
  background(0);
  stroke(255);

 player1delay();
 player2delay();

}

void delayatstart(){
  millis(4000);
}

void player1delay(){

  delayatstart();
  player.play();
  player.rewind();

}

void delayatstart2(){
 millis(10000); 
}

void player2delay(){

  delayatstart2();
  player2.play();
  player2.rewind();

}

Above is the code I'm trying to use, i replaced my delays with millis and have looked up forums but can't find one to match what I'm looking for!

Was it helpful?

Solution

First off, you're using the millis() method incorrectly. The millis() method does not take any arguments, so I don't know what you think millis(10000) is going to do. Take a look at the reference: http://www.processing.org/reference/millis_.html

The millis() function simply returns the number of milliseconds since the start of the program. You can use that to create delays by comparing that to some threshold value. This example program only draws a circle after 5 seconds have elapsed:

void draw(){

   background(0);

   if(millis() > 5000){
      ellipse(10, 10, 50, 50);
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top