We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to make a particle attractor with processing where some particles are moving randomly and they get attracted towards a master attarctor when they come close to it. Doing this was fairly easy and I have completed the code. The problem is with the minim sound play part where I need to play a sound file when the particles hit the master attractor. I am using only one audio file which needs to play whenever the particle hits the master attractor.
The problem is that when a particle hits the master attractor it plays the sound but as soon as another particle hits the sound it reset the sound and sound doesn't play properly.
when I do this processing plays multiple instance and it doesn't sound good.
if (P.loc.dist(M.loc)<50) {
stroke(0, 50);
line(P.loc.x, P.loc.y, M.loc.x, M.loc.y);
player.pause();
player.rewind();
player.play();
}
When I do this the whole processing sketch gets slowed down
if (P.loc.dist(M.loc)<50) {
stroke(0, 50);
line(P.loc.x, P.loc.y, M.loc.x, M.loc.y);
player = minim.loadFile("1.MP3", 2048);
player.pause();
}
And when I do this the sound plays only few times because it waits until the previous instance gets finished.
if (P.loc.dist(M.loc)<50) {
stroke(0, 50);
line(P.loc.x, P.loc.y, M.loc.x, M.loc.y);
if (!player.isPlaying()) {
player.pause();
player.rewind();
player.play();
}
}
Answers
false
.break
the loop.@GoToLoop I know I did that and it was working but is there any other way without using array of sound?
Each AudioPlayer instance can only play 1 file at a single time.
Either interrupt its play() by rewind() or have another AudioPlayer instance of it.