seekBar = helper.getView(R.id.video_sb);
handler.sendEmptyMessage(UPDATA_VIDEO_NUM);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
//拖动视频进度时,停止刷新
handler.removeMessages(UPDATA_VIDEO_NUM);
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
int progress = seekBar.getProgress();
mIjkVideoView.seekTo(progress);
handler.sendEmptyMessage(UPDATA_VIDEO_NUM);
}
});
/**
* 通过handler对播放进度和时间进行更新
*/
private Handlerhandler =new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if (msg.what ==UPDATA_VIDEO_NUM) {
//获取视频播放的当前时间
int currentTime = (int)mIjkVideoView.getCurrentPosition();
//获取视频的总时间
int totally = (int)mIjkVideoView.getDuration();
//设置播放进度
seekBar.setMax(totally);
seekBar.setProgress(currentTime);
//自己通知自己更新
handler.sendEmptyMessage(UPDATA_VIDEO_NUM);
}
}
};
网友评论