Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 352
Nitin Misra Avatar asked Oct 19 '14 16:10

Nitin Misra


People also ask

How do I get SeekBar to automatically move on songs?

Here is the runnable class. Runnable timerRunnable = new Runnable() { public void run() { // Get mediaplayer time and set the value // This will trigger itself every one second. updateHandler. postDelayed(this, 1000); } };

What is SeekBar in video player?

Well according to android.developers.com, A SeekBar is an extension of ProgressBar that adds a draggable thumb. The user can touch the thumb and drag left or right to set the current progress level or use the arrow keys. Placing focusable widgets to the left or right of a SeekBar is discouraged.


1 Answers

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);  
                        }
                    }
                });
            }
        }); 
like image 196
Nitin Misra Avatar answered Oct 05 '22 22:10

Nitin Misra