I am attempting to make a streaming music player, but am having a bit of trouble with the SeekBar I am trying to implement. Currently, it acts correctly on the first song played. I can seek correctly and it updates itself in another thread. The problem I am having is that when a new song starts, the SeekBar flickers from the last songs duration to the current songs current progress. Any help would be appreciated.
SeekBar Declaration
progress = (SeekBar) findViewById(R.id.seekBar1);
progress.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if(fromUser) {
media.seekTo(progress);
}
else {
}
}
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
});
SeekBar update in seperate Thread
int current = 0;
int total = media.getDuration();
progress.setMax(total);
progress.setIndeterminate(false);
while(media!=null && current < total){
try {
Thread.sleep(1000);
current = media.getCurrentPosition();
progress.setProgress(current);
} catch (Exception e) {
e.printStackTrace();
}
};