1

I set a sound when I check the button

    public void Button(View v) {  

        final MediaPlayer mpStart = MediaPlayer.create(this, R.raw.startsound); 
        mpStart.start();
        }

I want to wait some time before the sound starts. How can i do?

Luigi Grimaldi
  • 243
  • 2
  • 8

1 Answers1

1

One solution is to use Handler.postDelayed() method.

@Override 
public void onClick(View v) {

// This solution will leak memory!  Actually don't use!!!
Handler handler = new Handler(); 
handler.postDelayed(new Runnable() {
     @Override 
     public void run() { 

          final MediaPlayer mpStart = MediaPlayer.create(this, R.raw.startsound); 
          mpStart.start();
     } 
}, 2000); //Here change the time to wait in milliseconds 
}

For more Info look here: Pause a process

Martin
  • 80
  • 8