Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

custom seek bar for a streaming video file in android

How can we display a custom seek bar for a streaming video file in android?

like image 314
random Avatar asked Dec 03 '09 12:12

random


2 Answers

Hi you can use below code to implemen custom seekbar for your video view,

 videoView.setOnPreparedListener(new OnPreparedListener() {

            @Override
            public void onPrepared(MediaPlayer mp) {

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

    private Runnable onEverySecond=new Runnable() {

        @Override
        public void run() {

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

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

        }
    };

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 position
                videoView.seekTo(progress);
            }
        }
    });
like image 56
Talha Avatar answered Oct 14 '22 08:10

Talha


Just use the SeekBar class. You can then use setProgress() and setSecondaryProgress().

If you want to change the style, see this question: How to customize the look of a SeekBar in Android?

like image 41
Oleg Vaskevich Avatar answered Oct 14 '22 08:10

Oleg Vaskevich