Nitin Misra
Nitin Misra

Reputation: 4522

Show MediaPlayer Buffering in Seek bar as Secondary Progress

I'm using Video view to stream an HLS stream from wowza media server. I want to show the overall buffering just as in YouTube player, what i did is this and I'm able to access seek-bar object and i debugged the code it's not null

videoView.setOnPreparedListener(new OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                int topContainerId = getResources().getIdentifier("mediacontroller_progress", "id", "android");
                seekbar = (SeekBar) mediaController.findViewById(topContainerId);

                mp.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
                    @Override
                    public void onBufferingUpdate(MediaPlayer mp, int percent) {
                        if (percent<seekbar.getMax()) {
                            seekbar.setSecondaryProgress(percent);  
                        }
                    }
                });
            }
        }); 

The problem is i can't see any secondary progress in Media controller seekbar. If any clarification required required please write in comments. Help is really appreciated.

Upvotes: 5

Views: 4706

Answers (1)

Nitin Misra
Nitin Misra

Reputation: 4522

Use below code and you're goog to go

videoView.setOnPreparedListener(new OnPreparedListener() {
            @Override
            public void onPrepared(MediaPlayer mp) {
                int topContainerId = getResources().getIdentifier("mediacontroller_progress", "id", "android");
                seekbar = (SeekBar) mediaController.findViewById(topContainerId);

                mp.setOnBufferingUpdateListener(new OnBufferingUpdateListener() {
                    @Override
                    public void onBufferingUpdate(MediaPlayer mp, int percent) {
                        if (percent<seekbar.getMax()) {
                            seekbar.setSecondaryProgress(percent/100);  
                        }
                    }
                });
            }
        }); 

Upvotes: 9

Related Questions