Answer the question
In order to leave comments, you need to log in
Druste. How to organize live update seek bar'a from mediaPlayer.getPosition() android?
I guess I'll have to make a timer, there in one second and update the seek bar and label on it where like 1:23:5:20 (well, how much time has passed and how long the composition lasts). For I did not find any event. So, I think right. Or is there a more humane way?
Answer the question
In order to leave comments, you need to log in
The timer is not needed, everything will be done in a separate thread. The SeekBar has an onProgressChanged listener that will listen for changes. In that separate thread, we get the current track location and set it for the UI. This is all repeated with some delay (a second for example). I made such an application, so here are the source codes, MB will help you.
public void listenSeekBar() {
AppData.sAudioPlayer.getMediaPlayer()
.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mTotalDuration = mp.getDuration();
mTimelineSeekBar.setMax(mTotalDuration);
mHandler.postDelayed(runnable, 100);
}
});
}
private Runnable runnable = new Runnable() {
public void run() {
int progress = AppData.sAudioPlayer.getMediaPlayer().getCurrentPosition();
mTimelineSeekBar.setProgress(progress);
mHandler.postDelayed(this, 100);
}
};
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
updateTrackCurrentTime(progress);
updateTrackDuration();
if (fromUser) {
AppData.sAudioPlayer.getMediaPlayer().seekTo(progress);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question