尝试使用倒数计时器按视频长度创建水平进度条。
我有一个videoview和水平进度条,我想做的是使用倒数计时器按照视频长度运行进度条
long totalDuration = videoDataView.getDuration();
long currentDuration = videoDataView.getCurrentPosition();
int progress = (int) (ConstantMethods.getProgressPercentage(currentDuration, totalDuration));
CountDownTimer timer = new CountDownTimer(totalDuration,100) {
@Override
public void onTick(long millisUntilFinished) {
single_progress.setProgress(progress);
}
@Override
public void onFinish() {
}
};
timer.start();
我希望它按照视频长度运行,但是当我运行应用程序进度条时,它不会启动。
答案 0 :(得分:0)
<ProgressBar
android:id="@+id/progressbar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:max="100"
android:progress="0"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottom_header_relativelayout"
/>
ProgressBar mProgressBar;
CountDownTimer mCountDownTimer;
int i=0;
mProgressBar=(ProgressBar)findViewById(R.id.progressbar);
mProgressBar.setProgress(i);
mCountDownTimer=new CountDownTimer(5000,1000) {
@Override
public void onTick(long millisUntilFinished) {
Log.v("Log_tag", "Tick of Progress"+ i+ millisUntilFinished);
i++;
mProgressBar.setProgress((int)i*100/(5000/1000));
}
@Override
public void onFinish() {
//Do what you want
i++;
mProgressBar.setProgress(100);
}
};
mCountDownTimer.start();