解决方法
最后我想出来了!
我想出的解决方案是这样的:
首先,将搜索栏的最大进度设置为视频的持续时间
videoView.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { seekBar.setMax(videoView.getDuration()); seekBar.postDelayed(onEverySecond,1000); } });
这个runnable将继续更新进度条:
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可以用于使用户在媒体上查找.通过使用fromUser布尔值,我们可以确定是否由于用户的交互或回调
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); } } });