We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everyone!
So, I want to have a song to start playing after having pressed a button. I've got the following code, but the issue is that the song gets 'stuck'. This must have to do with the fact that is is in draw.
Looking forward to your replies!
Best wishes
import ddf.minim.*;
Minim minim;
AudioPlayer player;
boolean rect3Over = false;
boolean checked3 = false;
// Diameter of rectangles
int rectSize = 90;
// Position of play rect
int rect3X = 640/2 - rectSize/2;
int rect3Y = 250;
// Initialize width
int width = 640;
void setup()
{
size(width, 360);
minim = new Minim(this);
player = minim.loadFile("1.mp3");
}
void draw() {
background(255);
// Draw play rect
fill(175);
rect(rect3X, rect3Y, rectSize, rectSize);
// Test if the cursor is over play rect
if (mouseX > rect3X && mouseX < (rect3X + rectSize) &&
mouseY >rect3Y && mouseY < (rect3X + rectSize)) {
rect3Over = true;
} else {
rect3Over = false;
}
//play song
if (checked3) {
player.play();
}
}
// Check whether play rect is clicked
void mousePressed() {
if (rect3Over) {
checked3 = !checked3;
}
}
Answers
https://forum.Processing.org/two/discussion/14637/sound-on-a-key-press
Thanks, this is not my question however. I just want the song to stop playing whithout it making any strange sounds.
I solved the issue by placing .play(); out of draw. Thanks GoToLoop!
Never mind, that doesn't work. Question still requires answering!
I would suggest
1) Remove your checked3 variable
2)call play() in mousePressed() function.
I hope this helps!
Kf