How to play a custom sound after the countdown timer ends?
I am trying to implement the following functionality in my application
- The user selects a music file in one input field and time duration ( Seconds only ) in the other.
- After the user presses ok, the count down timer starts and runs t开发者_JAVA百科ill the entered time duration expires and then the chosen music file should start playing.
Can anybody please advise me on the best way to implementing this other than using the alarm manager?
final Timer timer = new Timer();
final TimerTask task = new TimerTask() {
@Override
public void run() {
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepare();
mp.start();
}
};
timer.schedule(task, delay);
精彩评论