我有以下代码将SeekBar添加到视频中:
final VideoView videoView = (VideoView) findViewById(R.id.videoView);
final MediaController mediaController = new MediaController(this) {
...
// Commented out irrelevant code.
}
mediaController.show();
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
final int topContainerId1 = getResources().getIdentifier("mediacontroller_progress",
"id", "android");
final SeekBar seekbar = (SeekBar) mediaController.findViewById(topContainerId1);
seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int overall_progress = 0;
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
...
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
videoView.seekTo((int) (videoView.getDuration() * (seekBar.getProgress() / 1000.0)));
}
});
}
});
一切正常,导演指示器在播放时与视频对齐。当我手动移动搜索按钮时,视频会移到正确的位置。
我的问题:如果我暂停视频然后再次开始播放,则即使视频再次播放,搜索栏进度指示器也不会再移动。我检查了在这种情况下是否调用了 onProgressChanges(),但它从未被调用过!有谁知道解决这个问题?看来这个人也有问题,但没有人回答他们的帖子:Seekbar OnProgressChanged doesn't get fired when moving manually