How can i make a efficient counter which is paused when media player is paused
<pre><code>i am working in android, i am designing a media player. I want to play a song only for 30 second. I have added a counter for this. but this is not working in the case if i press the pause button. means when i press pauses button then this counter should also be paused, and when i pressed stop then this counter should also be re-started.

this is the code which is designed by me.

public class StreamingMp3Player extends Activity implements OnClickListener, OnTouchListener, OnCompletionListener, OnBufferingUpdateListener{

    private ImageButton buttonPlayPause;
    private ImageButton buttonStop;
    private SeekBar seekBarProgress;
    //public EditText editTextSongURL;
    Bundle extras;
    String songURL;
    private MediaPlayer mediaPlayer;
    private int mediaFileLengthInMilliseconds; // this value contains the song duration in milliseconds. Look at getDuration() method in MediaPlayer class

    private final Handler handler = new Handler();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.musicplayerbar);
        initView();
    }

    /** This method initialise all the views in project*/
    private void initView() {
        buttonPlayPause = (ImageButton)findViewById(R.id.ButtonTestPlayPause);
        buttonStop=(ImageButton)findViewById(R.id.ButtonTestStop);
        buttonPlayPause.setOnClickListener(this);
        buttonStop.setOnClickListener(this);

        seekBarProgress = (SeekBar)findViewById(R.id.SeekBarTestPlay);  
        seekBarProgress.setMax(99); // It means 100% .0-99
        seekBarProgress.setOnTouchListener(this);
        //editTextSongURL = (EditText)findViewById(R.id.EditTextSongURL);
        //editTextSongURL.setText(R.string.testsong_20_sec);

        mediaPlayer = new MediaPlayer();
        mediaPlayer.setOnBufferingUpdateListener(this);
        mediaPlayer.setOnCompletionListener(this);
    }

    /** Method which updates the SeekBar primary progress by current song playing position*/
    private void primarySeekBarProgressUpdater() {
        seekBarProgress.setProgress((int)(((float)mediaPlayer.getCurrentPosition()/mediaFileLengthInMilliseconds)*100)); // This math construction give a percentage of "was playing"/"song length"
        if (mediaPlayer.isPlaying()) {
            Runnable notification = new Runnable() {
                public void run() {
                    primarySeekBarProgressUpdater();
                }
            };
            handler.postDelayed(notification,1000);
        }
    }

    @Override
    public void onClick(View v) {
        if(v.getId() == R.id.ButtonTestPlayPause){
             /** ImageButton onClick event handler. Method which start/pause mediaplayer playing */
            try {
                //mediaPlayer.setDataSource(editTextSongURL.getText().toString()); // setup song from http://www.hrupin.com/wp-content/uploads/mp3/testsong_20_sec.mp3 URL to mediaplayer data source
            /// mediaPlayer.setDataSource("http://192.168.1.126/MusicApplication/Akon.mp3");
                 extras=getIntent().getExtras();
                 songURL=extras.getString("songURL");
                 Log.v("in streaming of player",songURL);
                mediaPlayer.setDataSource(getString(R.string.SERVER_NAME)+getString(R.string.APP_FOLDER_NAME)+getString(R.string.SONG_FOLDER_NAME)+songURL);

                mediaPlayer.prepare(); // you must call this method after setup the datasource in setDataSource method. After calling prepare() the instance of MediaPlayer starts load data from URL to internal buffer.

            } catch (Exception e) {
                e.printStackTrace();
            }

        /// mediaFileLengthInMilliseconds = mediaPlayer.getDuration(); // gets the song length in milliseconds from URL
            mediaFileLengthInMilliseconds = 30000;
            CountDownTimer cntr_aCounter = null;
            if(!mediaPlayer.isPlaying()){
                cntr_aCounter = new CountDownTimer(30000, 1000) {
                    public void onTick(long millisUntilFinished) {
                        mediaPlayer.start();
                    }

                    public void onFinish() {
                        // code fire after finish
                        mediaPlayer.stop();
                    }
                };
                cntr_aCounter.start();
            //  mediaPlayer.start();
                buttonPlayPause.setImageResource(R.drawable.button_pause);
            }else {
                mediaPlayer.pause();

                buttonPlayPause.setImageResource(R.drawable.button_play);
            }

            primarySeekBarProgressUpdater();
        }
        if(v.getId() == R.id.ButtonTestStop)
        {
            mediaPlayer.stop();
        }
    }

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if(v.getId() == R.id.SeekBarTestPlay){
            /** Seekbar onTouch event handler. Method which seeks MediaPlayer to seekBar primary progress position*/
            if(mediaPlayer.isPlaying()){
                SeekBar sb = (SeekBar)v;
                int playPositionInMillisecconds = (mediaFileLengthInMilliseconds / 100) * sb.getProgress();
                mediaPlayer.seekTo(playPositionInMillisecconds);
            }
        }
        return false;
    }



    @Override
    public void onCompletion(MediaPlayer mp) {
         /** MediaPlayer onCompletion event handler. Method which calls then song playing is complete*/
        buttonPlayPause.setImageResource(R.drawable.button_play);
    }

    @Override
    public void onBufferingUpdate(MediaPlayer mp, int percent) {
        /** Method which updates the SeekBar secondary progress by current song loading from URL position*/
        seekBarProgress.setSecondaryProgress(percent);
    }
}


please suggest me what should i do for this .

Thank you in advance.
</code></pre>
