Answer the question
In order to leave comments, you need to log in
How can I wait until VKRequest is completed?
I have a VKRequest that starts playing an online song. I also have a SeekBar that updates the playback progress. The problem is that the method to update the SeekBar is called before my VKRequest is executed, which will start the song. And in more detail, first request.executeWithListener is executed (without onComplete), then my method for updating the SeekBar, and then the code in the onComplete method starts running. How can I wait until the onComplete method is finished (preferably with some kind of UI update in onProgress) and only then start executing the listenSeekBar method?
request.executeWithListener(new VKRequest.VKRequestListener() {
@Override
public void onComplete(VKResponse response) {
super.onComplete(response);
// тут прописана реализация запуска на проигрывание песни
}
@Override
public void onProgress(VKRequest.VKProgressType progressType, long bytesLoaded, long bytesTotal) {
super.onProgress(progressType, bytesLoaded, bytesTotal);
}
});
// метод для обновления SeekBar в другом классе
private void listenSeekBar() {
AppData.sAudioPlayer.getMediaPlayer()
.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mTotalDuration = mp.getDuration();
mTimelineSeekBar.setMax(mTotalDuration);
mHandler.postDelayed(runnable, 100);
}
});
}
Answer the question
In order to leave comments, you need to log in
The problem was solved in this way - I passed the fragment to the class where the audio file is launched and from there I called the method to update the UI, namely SeekBar, in another fragment.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question