Mithraa
Mithraa

Reputation: 439

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 till 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?

Upvotes: 0

Views: 2025

Answers (1)

Alex Orlov
Alex Orlov

Reputation: 18107

    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);

Upvotes: 1

Related Questions