Answer the question
In order to leave comments, you need to log in
How can you delay the listener's work for a certain time or until a certain condition?
The point in brief. I have an Android application that streams music from VK and has a fragment that has a SeekBar that shows the progress of the file. It works fine with local files.
private void playLocalFile() {
mMediaPlayer = MediaPlayer.create(getActivity(), R.raw.song);
mMediaPlayer.start();
mMediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mTotalDuration = mp.getDuration();
mTimelineSeekBar.setMax(mTotalDuration);
mHandler.postDelayed(runnable, 100);
}
});
}
private void playSong() {
if (AppData.audioPlayer.getMediaPlayer() != null) {
AppData.audioPlayer.getMediaPlayer().setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
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
developer.android.com/reference/android/media/Medi...
an example from Google
should help
, how to write players
https://github.com/googlesamples/android-Universal...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question