Skip to content Skip to sidebar Skip to footer

Change Style Of Android Mediacontroller

Is there a way to customize the MediaController? I need to change the style of buttons, SeekBar etc.

Solution 1:

What you can do is recurse the view hierarchy of your MediaController and set the SeekBar's drawable programmatically:

privatevoidstyleMediaController(View view) {
    if (view instanceof MediaController) {
        MediaControllerv= (MediaController) view;
        for(inti=0; i < v.getChildCount(); i++) {
            styleMediaController(v.getChildAt(i));
        }
    } elseif (view instanceof LinearLayout) {
            LinearLayoutll= (LinearLayout) view;
            for(inti=0; i < ll.getChildCount(); i++) {
                styleMediaController(ll.getChildAt(i));
            }
        } elseif (view instanceof SeekBar) {
            ((SeekBar) view).setProgressDrawable(getResources().getDrawable(R.drawable.progressbar)); 
            ((SeekBar) view).setThumb(getResources().getDrawable(R.drawable.progresshandle));
        }
}

Then, just call

styleMediaController(myMC);

Solution 2:

The method makeControllerView was meant to be overridden so you could supply your own view. Unfortunately, it is hidden at the moment.

You may want to take the source of MediaController and either reimplement it or copy-and-paste the hidden methods into a subclass so you can customize it.

Solution 3:

I changed the code of bk138's answer to just change the color of the elements. Not the drawables themselves. This solution is compatible to old devices in conjunction with the support library v4.

privatevoidstyleMediaController(View view) {
        if (view instanceof MediaController) {
            MediaControllerv= (MediaController) view;
            for (inti=0; i < v.getChildCount(); i++) {
                styleMediaController(v.getChildAt(i));
            }
        } elseif (view instanceof LinearLayout) {
            LinearLayoutll= (LinearLayout) view;
            for (inti=0; i < ll.getChildCount(); i++) {
                styleMediaController(ll.getChildAt(i));
            }
        } elseif (view instanceof SeekBar) {
            ((SeekBar) view)
                    .getProgressDrawable()
                    .mutate()
                    .setColorFilter(
                            getResources().getColor(
                                    R.color.MediaPlayerMeterColor),
                            PorterDuff.Mode.SRC_IN);
            Drawablethumb= ((SeekBar) view).getThumb().mutate();
            if (thumb instanceof android.support.v4.graphics.drawable.DrawableWrapper) {
                //compat mode, requires support library v4
                ((android.support.v4.graphics.drawable.DrawableWrapper) thumb).setCompatTint(getResources()
                        .getColor(R.color.MediaPlayerThumbColor));
            } else {
                //lollipop devices
                thumb.setColorFilter(
                        getResources().getColor(R.color.MediaPlayerThumbColor),
                        PorterDuff.Mode.SRC_IN);
            }
        }
    }

Then, just call

styleMediaController(myMC);

Had to call styleMediaController(myMC) in the OnPreparedListener of the VideoView to make it work. Otherwise the MediaController view has no children.

Post a Comment for "Change Style Of Android Mediacontroller"