How to set a timer for MediaPlayer in Android?
<p>I am developing a phone finder application, and i would like to implement the remote ringing function... I already write a code for MediaPlayer, but when I tested it, the alarm is ringing non-stop (maybe the time for the alarm song is too long but i wanna make it rings for a particular period only)... I hope to set a timer for the alarm ringing like let say ringing for 10 seconds, but no idea on how to achieve it... Need help from you guys... thanks...</p>

<pre><code>    MediaPlayer mp = new MediaPlayer();
    mp = MediaPlayer.create(RingerActivity.this, R.raw.alarm);
    try {
        mp.prepare();
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (Exception e) {
        Toast.makeText(this, e.getMessage() , Toast.LENGTH_SHORT).show();         }
    mp.start();

    mp.setOnCompletionListener(new OnCompletionListener() {
        public void onCompletion(MediaPlayer mp) {
            mp.release();
        }
    });
</code></pre>
