如何在Android中为流媒体视频文件显示自定义搜索栏?
答案 0 :(得分:8)
您好,您可以使用以下代码为您的视频视图实现自定义搜索栏,
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);
}
}
});
答案 1 :(得分:0)
只需使用SeekBar课程即可。然后,您可以使用setProgress()
和setSecondaryProgress()
。
如果您想更改样式,请参阅此问题:How to customize the look of a SeekBar in Android?