我正在写一个字幕阅读应用程序。我希望它的运行方式类似于玩家,但是我在计时方面很挣扎

下面的代码应在显示在屏幕上的确切毫秒内显示字幕。

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();

我怎么改变睡眠方式都没关系,在某些时候,时间安排会变得不同步。也许休眠线程不是执行此操作的好方法。

shiweialive 回答:我正在写一个字幕阅读应用程序。我希望它的运行方式类似于玩家,但是我在计时方面很挣扎

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3106139.html

大家都在问