下面的代码应在显示在屏幕上的确切毫秒内显示字幕。
public void ticktime(){
// Start long running operation in a background thread
new Thread(new Runnable() {
public void run() {
while (progressStatus < endtime) {
progressStatus += 1;
// Update the progress bar and display the
//current value in the text view
handler.post(new Runnable() {
public void run() {
mProgressBar.setProgress(progressStatus);
SubTitle st = Subtitlelist.get(NextSubtitle);
if (Integer.valueOf(st.SRTStart0.replaceFirst("[.].*","")) <= progressStatus){
mcontextReader.setText(st.SRText);
CurrentSubtitle = CurrentSubtitle+1;
NextSubtitle = CurrentSubtitle+1;
Log.d("NextSubStart1: ",st.SRTStart0.replaceFirst("[.].*",""));
}
}
});
try {
// Sleep for 200 milliseconds.
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
我怎么改变睡眠方式都没关系,在某些时候,时间安排会变得不同步。也许休眠线程不是执行此操作的好方法。