How to update correctly (setValue)?
cutiko opened this issue · 1 comments
cutiko commented
Greetings
My music app run a service where the music is played, Im having problem to update the progress. This is what Im doing:
ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
Runnable updater = new Runnable() {
@Override
public void run() {
//The current progress of the song in %
final float percent = playerService.getCurrentPosition() * 100 / playerService.getDuration();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
//If runOnUi is not done then the sheduler is stop
circularPb.setValue(percent);
}
});
}
};
updateHandler = scheduler.scheduleWithFixedDelay(updater, 2, 2, TimeUnit.SECONDS);
As you can see, that is not elegant at all, there is a scheduler in charge of repeating the process and inside of it I have to access the UI. Here is the full repo in case you want to take a deeper look (is WIP I have to do a lot of refactoring and cleaning).
I have being looking in your sample although the update concept is clear, is not what Im looking.
Do you have a suggestion?
mehmetgelmedi commented
Hey, you can do this for your music player
Update Progress Bar On UI