• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps on press not releas

i have a button setup to play a sound, *tittle ****release*
but nothing plays until i release the button again
here's my code
Code:
bKick.setOnClickListener(new View.OnClickListener() {

public void onClick(View v) {
	// TODO Auto-generated method stub
	sp.play(dance_kick, 1, 1, 1, 0, 1);
}

});
 
onClick only registers when a control is clicked (pressed and released). with onTouch, you can specifiy if you want to catch the down event or the up event.

allright, iv'e got the ontouch working, but it keeps playing the sound like a trillion times, until i release it, i really only want it to play once on press
 
isn't there a method that looks for the button press instead of release ?
i'm kinda confused by this ontouch flag thing,
or maybe if you could explain in a little more detail
:)

Code:
public boolean onTouch(View v, MotionEvent e)
{
    if(v == whateverYourButtonIsCalled && e.getAction() == MotionEvent.ACTION_DOWN)
    {
       /****PSUEDO CODE****/
        //Construct your meia player
        if(!sound.isPlaying())
            //play sound
       /*****END PSUEDO CODE***/
    }  
}

As noted, everything within the first condition is psuedo code, however I do know that the isPlaying() method exists for the MediaPlayer class, so I recommend using that. No flag is really necessary thanks to this method.
 
Code:
public boolean onTouch(View v, MotionEvent e)
{
    if(v == whateverYourButtonIsCalled && e.getAction() == MotionEvent.ACTION_DOWN)
    {
       /****PSUEDO CODE****/
        //Construct your meia player
        if(!sound.isPlaying())
            //play sound
       /*****END PSUEDO CODE***/
    }  
}

As noted, everything within the first condition is psuedo code, however I do know that the isPlaying() method exists for the MediaPlayer class, so I recommend using that. No flag is really necessary thanks to this method.
thanks man, got the thing working using the motion event' :D

Code:
bKick.setOnTouchListener(new View.OnTouchListener() {

	public boolean onTouch(View v, MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			sp.play(dance_kick, 1, 1, 1, 0, 1);
			return true;
		}
		return false;
	}
		
});
 
Back
Top Bottom