开发者

How to play a custom sound after the countdown timer ends?

I am trying to implement the following functionality in my application

  1. The user selects a music file in one input field and time duration ( Seconds only ) in the other.
  2. 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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜