I am trying to use two sounds when I button is pushed: one sound when the button is pressed and another when the button is release. How can I accomplish this?
I currently play a sound when a button is clicked with this:
button.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
mp = MediaPlayer.create(Test.this, R.raw.mysound);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// TODO Auto-generated method stub
mp.release();
}
});
}
});
Try using an
OnTouchListener:You can attach that to an
OnTouchListenerusingsetOnTouchListener()the same way you’ve demonstrated with theOnClickListeneryou have already.