Change android MediaController style

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

+8
android android widget
Jan 11 '10 at 18:37
source share
3 answers

The makeControllerView method had to be overridden so you can provide your own view. Unfortunately, it is now hidden.

You might want to take the source of the MediaController and either override it, or copy and paste the hidden methods into a subclass so that you can configure it.

+3
Jan 11 '10 at 20:00
source share

What you can do is rewrite the presentation hierarchy of your MediaController and program the SeekBar programmatically:

 private void styleMediaController(View view) { if (view instanceof MediaController) { MediaController v = (MediaController) view; for(int i = 0; i < v.getChildCount(); i++) { styleMediaController(v.getChildAt(i)); } } else if (view instanceof LinearLayout) { LinearLayout ll = (LinearLayout) view; for(int i = 0; i < ll.getChildCount(); i++) { styleMediaController(ll.getChildAt(i)); } } else if (view instanceof SeekBar) { ((SeekBar) view).setProgressDrawable(getResources().getDrawable(R.drawable.progressbar)); ((SeekBar) view).setThumb(getResources().getDrawable(R.drawable.progresshandle)); } } 

Then just call

 styleMediaController(myMC); 
+4
03 Oct '12 at 23:28
source share

I changed the response code bk138 to just change the color of the elements. Not the drawings themselves. This solution is compatible with older devices in combination with the v4 support library.

 private void styleMediaController(View view) { if (view instanceof MediaController) { MediaController v = (MediaController) view; for (int i = 0; i < v.getChildCount(); i++) { styleMediaController(v.getChildAt(i)); } } else if (view instanceof LinearLayout) { LinearLayout ll = (LinearLayout) view; for (int i = 0; i < ll.getChildCount(); i++) { styleMediaController(ll.getChildAt(i)); } } else if (view instanceof SeekBar) { ((SeekBar) view) .getProgressDrawable() .mutate() .setColorFilter( getResources().getColor( R.color.MediaPlayerMeterColor), PorterDuff.Mode.SRC_IN); Drawable thumb = ((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); 

I had to call styleMediaController(myMC) in the OnPreparedListener VideoView to make it work. Otherwise, there are no children in the MediaController view.

+1
Mar 23 '16 at 8:37
source share



All Articles