I am trying to create a simple music player app. I want to display the current runtime of the song on the left and the remaining duration of the song to the right. In mm:ss format. I am invoking a thread which periodically updates the seekbar and the left/right times. the song is 4min 36 seconds long. So what I want to see is something like 0:00 in left and 4:36 in right in the beginning. Left time keeps on increasing by 1 second and simultaneously right decreases by 1 sec. but what I am seeing is 30:00 at left and 34:36 to right. An additional 30 mins are getting added to both the times initially. Why is this happening? Am I missing anything here?
public void updateThread(){
thread = new Thread(){
@Override
public void run() {enter code here
try{
while(mediaPlayer != null && mediaPlayer.isPlaying()){
Thread.sleep(50);
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), String.valueOf(mediaPlayer.getCurrentPosition()), Toast.LENGTH_LONG).show();
seekBar.setMax(mediaPlayer.getDuration());
seekBar.setProgress(mediaPlayer.getCurrentPosition());
leftTime.setText(String.valueOf(new SimpleDateFormat("m:ss").format(new Date(mediaPlayer.getCurrentPosition()))));
rightTime.setText(String.valueOf(new SimpleDateFormat("m:ss").format(new Date(mediaPlayer.getDuration() - mediaPlayer.getCurrentPosition()))));
}
});
}
}
catch (InterruptedException e){
e.printStackTrace();
}
}
};
thread.start();**