문제

enter image description here

Hi there. As you can see i want to show buffered level of media that stream to user in android music player.
The solution i imagine for this issue is that:
Should i create a seekbar and a progressbar with transparent background and overlap progressbar to seek bar, whereas progreesbar showing buffered level of music.

but im not sure about this strategy. is anyone to help me for best way to reaching the goal at this issue.

도움이 되었습니까?

해결책

First of all should implements OnBufferingUpdateListener to activity then set onBufferingUpdate ike this:

public void onBufferingUpdate(MediaPlayer arg0, int percent) {
    /** Method which updates the SeekBar secondary progress by current song loading from URL position*/
    seekBarProgress.setSecondaryProgress(percent);
}

다른 팁

Just because setting percentage directly doesn't work. Here is the code that worked for me.

mediaPlayer.setOnBufferingUpdateListener(new MediaPlayer.OnBufferingUpdateListener() {
        @Override
        public void onBufferingUpdate(MediaPlayer mediaPlayer, int percent) {
            double per = percent * 1.00;
            per = (per / 100);
            double f = (seekBar.getMax() * 1.00);
            f = f * per;
            if (percent < binder.seekBar.getMax()) {
                seekBar.setSecondaryProgress((int) f);
            }
        }
    });

These int to double conversions are necessary because int division by 100 will give you 0 if result was to be 0.12 or 0.xx.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top