开发者

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

开发者 https://www.devze.com 2023-02-09 05:25 出处:网络
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.

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

精彩评论

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