質問

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