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 & HelpSound,  Music Libraries › sonia- playing sound problem
Page Index Toggle Pages: 1
sonia- playing sound problem (Read 697 times)
sonia- playing sound problem
Jun 4th, 2007, 5:14am
 
we have a very simple problem, we just dont know how to solve it. the code we are using a the moment is straight from the play() example on sonia. however, we want to use it with other code and so we would like the sound to play when the mouse is pressed. we want to put it in the draw function with the other items,

as in

if (mousePressed)
{ play
}

we tried putting the play function in draw but it doesnt work.

any advice? it would be greatly appreciated.
thanks
Re: sonia- playing sound problem
Reply #1 - Jun 9th, 2007, 6:04pm
 
this should work:


//////////////
import pitaru.sonia_v2_9.*;

//////////////
Sample mySample;  

boolean isOn = false;
 
void setup() {  
 size(100,100);  
 Sonia.start(this);  
 mySample = new Sample("glitch.wav");  
 mySample.play();
}  

void draw()
{
}

void mousePressed()
{  
 if( isOn == true ) mySample.play();
 else if( isOn == false )mySample.stop();

 isOn = !isOn;

 // debug
 println( isOn );
}


public void stop()
{  
 Sonia.stop();  
 super.stop();  
}
Page Index Toggle Pages: 1