Skip to content Skip to sidebar Skip to footer

How To Use A Seekbar In Android As A Seekbar As Well As A Progressbar Simultaneously?

I intend to write a custom media controller for my app. I was planning to use seekbar to do both seeking and showing progress. Trying to implement this. Does anyone have such imple

Solution 1:

Finally I figured it out!!

The solution that I came up with was something like this :

First of all set the max progress for seekbar as the duration of the video

videoView.setOnPreparedListener(newOnPreparedListener() {

        @OverridepublicvoidonPrepared(MediaPlayer mp) {

            seekBar.setMax(videoView.getDuration());
            seekBar.postDelayed(onEverySecond, 1000);
        }
    });

This runnable will keep on updating the progressbar :

privateRunnable onEverySecond=newRunnable() {

    @Overridepublicvoidrun() {

        if(seekBar != null) {
            seekBar.setProgress(videoView.getCurrentPosition());
        }

        if(videoView.isPlaying()) {
            seekBar.postDelayed(onEverySecond, 1000);
        }

    }
};

And then the setOnSeekBarChangeListener for the seekbar can be used to take the user seeks on the media. By using the fromUser boolean we can make out whether it was a call back due to user's interaction or the

seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress,
                boolean fromUser) {

            if(fromUser) {
                // this is when actually seekbar has been seeked to a new positionvideoView.seekTo(progress);
            }
        }
    });

Solution 2:

You set the seconday progress.

No, you're on the right track. It is very good for displaying stuff like download progress and current location for streams (media).

Post a Comment for "How To Use A Seekbar In Android As A Seekbar As Well As A Progressbar Simultaneously?"