How can we display a custom seek bar for a streaming video file in android?
Asked
Active
Viewed 9,706 times
2 Answers
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