Problem playing sound on Timer
<p>I have started a Timer on a screen , for example 20 seconds.</p>

<p>When the time remaining is 5 seconds , I am playing a beep sound .
The problem is that the sound is being played multiple times(3-4 times) , whereas I need a single beep . The duration of the audio file is 0.09 seconds.</p>

<p>Kindly find below the code </p>

<pre><code>public void onTick(long millisUntilFinished) {

            long timeLeft = millisUntilFinished / 1000;

            if (timeLeft == 5) {
                   playAlertSound(R.raw.beep);

                }
    }

    private MediaPlayer mPlayer;

    public void playAlertSound(int sound) {

        MediaPlayer mp = MediaPlayer.create(getBaseContext(), sound);
        mp.setOnCompletionListener(new OnCompletionListener() {

            @Override
            public void onCompletion(MediaPlayer mp) {
                // TODO Auto-generated method stub
                mp.release();
            }

        });
        // and add the setLooping and setVolume calls here..
        mp.setLooping(false);
        mp.setVolume(1.0f, 1.0f);
        mp.start(); // to here..
}
</code></pre>

<p>Kindly provide your inputs/suggestions , where the problem is</p>

<p>Thanks in advance.</p>

<p>Warm Regards,</p>

<p>CB</p>
