5

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

random
  • 10,238
  • 8
  • 57
  • 101
  • how are you streaming the video, and what's the format, and what's the player? Is it the normal MediaPlayer java class, for example? – Will Dec 03 '09 at 12:47

2 Answers2

10

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);
            }
        }
    });
Talha
  • 12,673
  • 5
  • 49
  • 68
1

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?

Community
  • 1
  • 1
Oleg Vaskevich
  • 12,444
  • 6
  • 63
  • 80