To show playback time, I used Timer and TimerTask , which updates the TextView tv every 1000 ms. Please note that not using tv.post (Runnable action) to set text in text form will not block the user interface stream and may cause problems.
if (player != null) { player.start(); timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { @Override public void run() { if (player != null && player.isPlaying()) { tv.post(new Runnable() { @Override public void run() { tv.setText(player.getCurrentPosition()); } }); } else { timer.cancel(); timer.purge(); } } }); } }, 0, 1000); }
Micer source share