In my application, I maid MediaPlayer playing from the Service, to update the SeekBar I assigned a timer task in the service
timer = new Timer();
timer.scheduleAtFixedRate(new RemindTask(), 0, 1 * 1000);
class RemindTask extends TimerTask {
@Override
public void run() {
if (mediaPlayer!=null && mediaPlayer.isPlaying()){
MusicPlayerActivity.progress=mediaPlayer.getCurrentPosition();
MusicPlayerActivity.total=mediaPlayer.getDuration();
}
}
}
and using runnable list, I made a run method on the activity page,
@Override
public void run()
{
runOnUiThread(new Runnable() {
@Override
public void run() {
seekBar.setMax(total);
seekBar.setProgress(progress);
}
});
}
But my problem is that the application is very slow and stuck.
user5299762
source
share