How to Create Custom UI for Android Mediacontroller

Custom UI on exoplayer sample

Actually the code of involking play & pause methods are in class PlayerControl.

If you don't want to use default Android media controller UI, just don't use the MediaController class, create your own UI in your layout file with custom play & pause button and bind the actions with the button's onClickListener.

To play the video, call exoPlayer.setPlayWhenReady(true);

And to pause: call exoPlayer.setPlayWhenReady(false);

It's similar problem with how to create custom UI for android MediaController

Android MediaController custom graphics

The best will be to copy source code of MediaController and change layout according to Your needs. Not easy but the best way :)

You can also try get

ImageButton mRewButton;

by reflection and try to change it but i will not recommend that. Here is how this can be done:

try {
Field field = mediaController.getClass().getDeclaredField("mRewButton");
field.setAccessible(true);
Object value = field.get(mediaController);
if (value instanceof ImageButton) {
// do some changes here
((ImageButton) value).setImageResource(R.mipmap.ic_launcher);
}
} catch (NoSuchFieldException e) {
//handle errors gently
e.printStackTrace();
} catch (IllegalAccessException e) {
//handle errors gently
e.printStackTrace();
}

Just make sure that before that Your controller is initialized. Result looks like this:

enter image description here



Related Topics



Leave a reply



Submit