We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › how to run multiple sounds in one sketch
Page Index Toggle Pages: 1
how to run multiple sounds in one sketch (Read 1153 times)
how to run multiple sounds in one sketch
Apr 10th, 2010, 9:33pm
 
Hi guys,
I want to make a processing game that run a music file in the background and if the user pressed on left button play specific sound file, and if he pressed right button play another one
I used minim, but could not get what i want, below is my code:



import ddf.minim.*;
AudioPlayer player;
Minim minim;

     if (mouseButton == LEFT)
            {
                  player = minim.loadFile("chainsaw.wav",1);
                 player.play();
                 
            }
        else if (mouseButton == RIGHT)
            {
                  player = minim.loadFile("beep.wav", 2048);
                  player.close();// to close first one and then play the other
                   player.play();
             
             }


Could any one see what happend? and what about:
minim.stop();
super.stop();

Thanks
Re: how to run multiple sounds in one sketch
Reply #1 - Apr 11th, 2010, 1:38am
 
If all your code is there, you miss a setup() to load the files and a draw() to activate the mouse events...
If not, you should tell us more about the exact issue you have.
Re: how to run multiple sounds in one sketch
Reply #2 - Apr 11th, 2010, 3:16am
 
Sorry.
Below is my code, one of the sound working in a wrong way, not continuous, and the other is not working at all


Code:
import ddf.minim.*;
AudioPlayer player;
Minim minim;

void setup (){
size (700, 500);
minim = new Minim(this);


}

void draw(){

if (mouseButton == LEFT)
{
player = minim.loadFile("chainsaw.wav",1);
player.play();

}
else if (mouseButton == RIGHT)
{
player = minim.loadFile("beep.wav", 2048);
player.close();// to close first one and then play the other
player.play();


}


}
Re: how to run multiple sounds in one sketch
Reply #3 - Apr 11th, 2010, 3:44am
 
As said, you should load the files in setup(), avoiding a lag in draw(). Thus you need to have two players.
Beside, you close the player right after loading the new one, so you close the new one, not the old one.
Page Index Toggle Pages: 1