简体   繁体   中英

Add a delay before playing an audio using Android MediaPlayer

I want to play 5 audio's at a go but with different time delays. Like (a.mp3 with a time delay of 2 sec, b.mp3 = 4 sec etc) but i dont know how to do it.

You can use handler.

Handler handler = new Handler();
final static int DELAY = 1000; // one second

public void playAudioWithDelay(){
  handler.postDelayed(new Runnable(){
    //your code start with delay in one second after calling this method
  }, DELAY);
  handler.postDelayed(new Runnable(){
    //your code start with delay in two seconds after calling this method
  }, DELAY * 2);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM