We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I want to play some sounds when i click the mouse, but I get a NullPointerException error at the line with "second.close();" I know that this code can be done more easily, but I really need it like this, because I will add other things too. Can someone tell me what's wrong?
import ddf.minim.*;
Minim minim;
AudioPlayer first, second, third, fourth, fifth;
int n=0;
void setup(){
size(200,200);
background(0);
minim = new Minim(this);
first = minim.loadFile("first.mp3");
second = minim.loadFile("second.mp3");
third = minim.loadFile("third.mp3");
fourth = minim.loadFile("fourth.mp3");
fifth = minim.loadFile("fifth.mp3");
}
void draw(){
}
void mouseClicked(){
if(n==0){
first.play();
} else {
first.close();
}
if(n==1){
second.play();
} else {
second.close();
}
if(n==2){
third.play();
} else {
third.close();
}
if(n==3){
fourth.play();
} else {
fourth.close();
}
if(n==4){
fifth.play();
} else {
fifth.close();
}
n++;
}
Answers
Please edit your post to format the code
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
you don't declare third and so on...?
oh, sorry. i did that in the original code, but i forgot to do it here... so i dont think that that is the problem
Please post the actual code you're using.
You're closing every sound except one each time you click the mouse. But once you close a sound for the first time, what should happen when you close it again? I wouldn't be surprised if it throws an exception.
I'm not a minim expert, so I'm honestly not sure, but googling "Processing minim AudioPlayer NullPointerException" wouldn't be a bad place to start.
try
second.pause();
instead?KevinWorkman was right. all i had to do is re-load the sound files after closing them. my bad, sorry...
A simple example of using AudioPlayer[] + pause() + rewind(): :-bd
http://forum.processing.org/two/discussion/8506/how-do-i-make-sure-only-1-audio-file-is-played-at-a-single-time
oh, thank you! this made things A LOT easier! :)
Hello Guys.
I got a little problem. I'm working with Processing 1.5.1 and I've downloaded the minim 2.2.2 library. When I want to run examples with the ddf.minim.ugens. import, the program tell me that the library is missing. But I've checked my libraries and the ugen folder is in my document with this architecture : document/Minim-2.2.2/src/ddf/minim/ugens
I don't undestand. Sorry for my english anyway. Thanks.