Buffered level of music showing in seekbar

妖精的绣舞 提交于 2019-12-08 01:59:09

问题


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.


回答1:


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);
}



回答2:


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.



来源:https://stackoverflow.com/questions/21828713/buffered-level-of-music-showing-in-seekbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!