I run the stream that I create with this method:
void UIInitialize(){ UIUpdater = new Thread(new Runnable() { @Override public void run() { while (!UIUpdater.isInterrupted()) { //блок паузы потока для того, что-бы включать его только на время работы synchronized (UIMonitor) { while (!isUpdUI) { try { UIMonitor.wait(); } catch (InterruptedException e) { e.printStackTrace(); return; } } } if (mediaPlayer != null) { runOnUiThread(new Runnable() { @Override public void run() { int CurrentProgress = mediaPlayer.getCurrentPosition(); Log.e("Thread", "SendUiUpd: "+CurrentProgress); tvProgress.setText(String.valueOf(CurrentProgress)); } }); } else { isUpdUI=false;} try { Thread.sleep(15); } catch (InterruptedException e) { return; } } } }); UIUpdater.start(); } To log
04-17 18:27:09.907 27365-27365/etere.wingscontrol E/Thread: SendUiUpd:2873 04-17 18:27:09.924 27365-27365/etere.wingscontrol E/Thread: SendUiUpd:2890 04-17 18:27:09.940 27365-27365/etere.wingscontrol E/Thread: SendUiUpd:2906 04-17 18:27:09.957 27365-27365/etere.wingscontrol E/Thread: SendUiUpd:2926 04-17 18:27:09.959 27365-27365/etere.wingscontrol E/Thread: SendUiUpd:2926 04-17 18:27:09.973 27365-27365/etere.wingscontrol E/Thread: SendUiUpd:2926 04-17 18:27:09.988 27365-27365/etere.wingscontrol E/Thread: SendUiUpd:2926 04-17 18:27:10.003 27365-27365/etere.wingscontrol E/Thread: SendUiUpd:2926 04-17 18:27:10.022 27365-27365/etere.wingscontrol E/Thread: SendUiUpd:2926 By making the delay equal to 1, it was possible to notice the pattern, it slips a gap of 0.5–0.7 seconds correctly with a quick change of numbers, and then hangs for 0.3–0.7 seconds, and then quickly works correctly again (it looks like a problem in buffering?)
As a result of studying the logs, it was noticed that by the time of the pause, getCurrentTime is longer than the actual elapsed time, and the output becomes equal ... or even such a joke ... ( 04-17 20:26:37.559 E/Thread: SendUiUpd: 0 - первый апдейт )
04-17 20:26:39.212 E/Thread: SendUiUpd: 1658 04-17 20:26:39.218 E/Thread: SendUiUpd: 1664 - рельное время - 1.659 04-17 20:26:39.220 E/Thread: SendUiUpd: 1608 - рельное время - 1.661 04-17 20:26:39.221 E/Thread: SendUiUpd: 1608 - вис на 223 милисек 04-17 20:26:39.222 E/Thread: SendUiUpd: 1608 Why is updating so uneven and how to fix it?